Home Download Buy Blog Forum Support

Equivalent to vim tabstop option

Equivalent to vim tabstop option

Postby AbsoluteDestiny on Mon May 17, 2010 12:41 pm

Is there a way that I can configure Sublime to operate like option 1 here:

http://vimdoc.sourceforge.net/htmldoc/o ... tabstop%27

Implementation would ideally mean that it would use 4 spaces when you press tab but would automatically convert 8 spaces to a \t (and have a tab width of 8 for display)

If not, does it sound like something that could be achieved with a plugin?

(I ask mostly because I'm collaborating on a project where I want to have my whitespace match that of the other authors without too much headache)
AbsoluteDestiny
 
Posts: 12
Joined: Fri Oct 23, 2009 2:27 pm

Re: Equivalent to vim tabstop option

Postby guillermooo on Mon May 17, 2010 2:55 pm

Would this help?

Code: Select all
tabSize: The number of spaces a tab is considered equal to. Defaults to 4.
translateTabsToSpaces: Set to true to insert spaces when tab is pressed. Defaults to false.


I usually configure this the other way around (tabs -> spaces), but it should work equally well if you want the opposite.

More info here:

http://www.sublimetext.com/docs/file-type-preferences
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: Equivalent to vim tabstop option

Postby guillermooo on Mon May 17, 2010 2:57 pm

Hm... It's been a while since I've used Vim, and I think you mean something slightly different that what I'm saying.
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: Equivalent to vim tabstop option

Postby AbsoluteDestiny on Mon May 17, 2010 3:32 pm

I don't use vim either, but to demonstrate a little what I think needs to happen to match the indentation:

When I press tab several times to indent, the following needs to happen (where the dots are the spaces based on whatever the width of soft tab is set to, here it's 4 and the \t is a tab)
Code: Select all
....
\t
\t....
\t\t
\t\t....
\t\t\t
AbsoluteDestiny
 
Posts: 12
Joined: Fri Oct 23, 2009 2:27 pm

Re: Equivalent to vim tabstop option

Postby tgkeul on Mon May 17, 2010 7:11 pm

Sublime has currently no concept of shiftwidth, a plugin is needed.
The implementation may be tricky, as a simple replace of \t with 8 spaces gives an undesired result having a situation like this (ts=8 sw=4)
Code: Select all
..\t..\t\t

As I remember vi you can insert some spaces before \t without changing the visible format.
tgkeul
 
Posts: 140
Joined: Tue Dec 02, 2008 9:35 pm

Re: Equivalent to vim tabstop option

Postby gpfsmurf on Mon May 17, 2010 7:21 pm

You can configure Sublime so that tabSize = 4, and use spaces instead of tabs.
Then, you create a plugin which has an onPreSave() which will replace leading strings of 8 spaces to a hard tab.
gpfsmurf
 
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm

Re: Equivalent to vim tabstop option

Postby AbsoluteDestiny on Tue May 18, 2010 9:22 am

Hmmm. I've tried doing view.replace(region, "\t") but when I have translateTabsToSpaces set to True, it converts my \t to four spaces after my function runs :(

I will investigate further.
AbsoluteDestiny
 
Posts: 12
Joined: Fri Oct 23, 2009 2:27 pm

Re: Equivalent to vim tabstop option

Postby gpfsmurf on Tue May 18, 2010 7:42 pm

Hmm you could programmatically change "translateTabsToSpaces" to false and then back to true...

Actually a better way to do this would be to set "translateTabsToSpaces" to False, set the tab size to 8, and overload the tab key to insert 4 spaces instead of a tab.
You would still need the onPreSave to replace the 8-spaces to a tab char.

But at least, this way, you'll see the source properly indented
gpfsmurf
 
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm

Re: Equivalent to vim tabstop option

Postby AbsoluteDestiny on Wed May 19, 2010 10:09 am

Yeah, the only way to have this work is to not use the indent command on tab and instead have my own, but I suspect that's going to be a massive pain.

I could maybe subclass it. I'll look into that.
AbsoluteDestiny
 
Posts: 12
Joined: Fri Oct 23, 2009 2:27 pm

Re: Equivalent to vim tabstop option

Postby AbsoluteDestiny on Thu May 20, 2010 2:43 pm

I'm finding this all very screwy, really.

If I have tab insert \t and I have tabsize set to 8 and I bind a key to insert four spaces, it makes a tab.

There's just too much mysterious replacing of things I want to insert to make this really work I think... which makes editing these files pretty horrible.
AbsoluteDestiny
 
Posts: 12
Joined: Fri Oct 23, 2009 2:27 pm

Next

Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 20 guests