Sublime Forum

Equivalent to vim tabstop option

#1

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

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)

0 Likes

#2

Would this help?

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:

sublimetext.com/docs/file-type-preferences

0 Likes

#3

Hm… It’s been a while since I’ve used Vim, and I think you mean something slightly different that what I’m saying.

0 Likes

#4

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)

.... \t \t.... \t\t \t\t.... \t\t\t

0 Likes

#5

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)

..\t..\t\t

As I remember vi you can insert some spaces before \t without changing the visible format.

0 Likes

#6

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.

0 Likes

#7

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 :frowning:

I will investigate further.

0 Likes

#8

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

0 Likes

#9

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.

0 Likes

#10

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.

0 Likes

#11

Maybe detectIndentation is interfering? Just a suggestion…

0 Likes