Sublime Forum

How to set tab size different from indent amount?

#1

I have files that assume that the tab character should indent by 8 spaces but the code uses four space indenting. How do I set the hardware tab width to be different from the indent level?

0 Likes

#2

do you mean that, you have a file which is indented with 4 spaces, and you want it so that when you press Tab, it would insert 8 spaces?

0 Likes

#3

Not exactly. The file is indented with 4 spaces but it assumes that a hardware tab character is 8 spaces wide so a line that is indented two levels will begin with a tab. A line that is indented only one level will begin with 4 spaces. This seems to be very common. I don’t do this myself when I create new files but sometimes I’m not supposed to be changing existing files and need to edit them the way they are. So, what I’m saying is that a line that is indented to an arbitrary level will begin with (level / 2) tabs followed by (level % 2) * 4 spaces. Other editors that I’ve used allow me to set the hardware tab width separately from the amount of indent that I get when pressing the tab key. Is there a way to do that with Sublime?

0 Likes

#4

Ugh. Kill it with fire. Mixed indentation is one of mankind’s greatest sin.

Other than that, you might be able to hack this together with a plugin and a few key bindings, but the process will be rather manual. Also note that you must be using tab indentation in ST’s settings because it will translate every tab character inserted with spaces (yes, even with plugins).

2 Likes

#5

Yeah, it is a bit of a pain. I have stopped inserting hardware tabs into text files and only use spaces for indentation. This seems particularly important when editing Python code since indenting determines block structure. Maybe I’ll just translate the tabs in these documents and endure any complaints I might get from the original authors!

0 Likes