Sublime Forum

Separate tab stops, indent size and character settings

#1

This is a minor request and it seems more like a silly/minor oversight than a truly massive failure, but it would be nice if Sublime had the ability to have different settings for tab width, indent size, indent type (spaces vs. tabs), and what happens when you hit the Tab key. This is something than many free editors (vim, Emacs, Komodo, Kate) have but Sublime seems to be lacking (unless it’s in a plugin somewhere that I’ve missed). For an example of what I mean, let’s say I want this behavior:

  • Tab characters
    : 8 spaces on screen

  • Indent characters
    : spaces

  • Indent size: 4 spaces

  • Tab key behavior: indent using the current indent size and characters settings

I’ve definitely come across several coding style requirements in my career where they want 4 space indents but still want 8 character wide tabs.

2 Likes

Can I set the indent like Whitesmiths style?
#2

So basically you want the current behaviour for

"translate_tabs_to_spaces": true,
"tab_size": 4

but want literal tabs (\t) that already are in the file to be displayed with a width of 8?

That sounds crazy (and mixed spaces are terrible!).

0 Likes

#3

Actually, that is not crazy. It was a coding standard at a place I worked in the past. It is also a coding standard used by the Linux kernel. It is also supported by several free editors, including Kate, Komodo Edit, Emacs, and Vim.

0 Likes

#4

it’s all coding programming.

0 Likes

#5

Also missing that feature so much… Some editors by default indent with 2 spaces and replace each indent sequence of 8 spaces with a tab (e.g. http://www.emacswiki.org/emacs/IndentationBasics).

If you want to read code written with such editors coherently with its indentation, you have to set ST tab size to 8.
If you want to write modifications in this the code, you have to set ST tab size to 2.

A tab width separable from indent size would solve the main part of the issue (just the “replace 8 spaces with tab” feature would be missing, but a simple plugin could do the job for this one, I guess).

0 Likes

#6

I would also like to see this functionality. While I don’t mix tabs and spaces (that does sound nuts), I am used to being able to separately control indentation and tabs. E.g., if I select a line (or more) and hit tab, it will indent two spaces; if I hit tab without a selection, it will indent to the nearest multiple of 8 characters. My firm does things like lining up colons and equal signs in variable assignments, and being able to hit tab to quickly get to the nearest tab stop is incredibly convenient, and the one thing that has kept me from using Sublime Text exclusively (I find myself often going back to TextPad, which supports this feature).

0 Likes

#7

Just chiming in that I’d like to see this, something like how you can configure sw, sts, and ts separately in vim. It seems to me this should be something you can either define in Sublime’s settings or leave alone to behave as it does today, at least giving us the option to change it if we desire.

The simple fact is that sometimes people are forced to maintain old code bases that use different standards than what is common today. In our case, going back and fixing 30 years of spacing just isn’t feasible.

Also, there are a few results in the userecho site for feature requests, this one is the most popular but only has 11 votes :frowning:

sublimetext.userecho.com/topic/4 … pace-code/

0 Likes

#8

I ended up writing a plugin to do this, if anyone cares to try it out. I’m rather new to Python, so there are bound to be mistakes but it’s pretty straightforward right now.

github.com/Wintaru/Vimdentation

0 Likes

#9

Thanks a lot!

0 Likes

#10

I don’t mix tabs and spaces (that does sound nuts), I am used to being able to separately control indentation and tabs. E.g., if I select a line (or more) and hit tab, it will indent two spaces; if I hit tab without a selection, it will indent to the nearest multiple of 8 characters. My firm does things like lining up colons and equal signs in variable assignments,

0 Likes

#11

I also created a plugin (Indentation Size Setting) available at github.com/Kronuz/IndentSize and soon on Package Control, if you guys want to check it out.

0 Likes

#12

Glad you found my meager offering a good starting point. I think the only thing I have working in Vimdentation that yours doesn’t do is that shift+tab still goes back 8 spaces when I usually only want it going back 4. This was my first attempt at any Python programming so it’s a bit rough around the edges, I think yours is a better example for people to follow and use. Thanks for writing it!

0 Likes

Indentation level different than tab_size
#13

One downside with solving this as a plug-in is that the indentation guides does not work. They use the same canonical setting as everything else related to indentation in Sublime Text, tab_width. This means that the indentation guides only show up every second level (even though the plug-ins posted above solves the indentation functionality for the most part).

In my opinion, not having this feature to work with the vast amount of code out there that uses the standard (regardless of its merits or not) is a real wart on the otherwise great feature list of Sublime Text. It’s strange that a mode that’s used by one of the largest code bases in the world, the Linux kernel, is not supported in Sublime Text.

@jps @wbond Will this ever make it into the core editor? It seems to me it is impossible to implement correctly with a plug-in right now…

1 Like

#14

I second this, the plugin approach is workable but it is so aggravating. I work in a company of 50+ developers, they’re not going to all change their editors or allow me to do a “whitespace commit” to fix this, nor should they have to deal with it. This is literally my only gripe with using Sublime Text at work.

0 Likes

#15

I’m going to be running into the same situation. A bunch of legacy code that I will be helping to maintain. There is a strict coding standard. Tabstops are 8 and indentation is 4 (meaning every two indention levels will replace the spaces with a tab).

VIM appears to have support for this…

My approach – I think, is to have a plugin that will initially set the tapstops to 8, convert to spaces then set tabstops to 4, then on save set the tabstops to 8 and convert spaces to tabs… – I’m hoping that will do the right trick.

0 Likes