Sublime Forum

'"translate_tabs_to_spaces": false' vs. Inserting a literal tab character

#1

I have

"translate_tabs_to_spaces": false

in my Preferences.sublime-settings, but if the file is indented using spaces, pressing the Tab key inserts spaces, not the tab itself.

  • Why is that?
  • How it is expected to work?
0 Likes

#2

ST dedects indentation style (tabs or spaces) and width of opened files by default (see: "detect_indentation") and adjusts "tab_size" and "translate_tabs_to_spaces" for the view accordingly.

1 Like

#4

What I don’t understand is why it adjusts translate_tabs_to_space for the current indentation style? Isn’t it the whole purpose of translate_tabs_to_space is to force tabs or spaces regardless of the current indentation style? And if it doesn’t force tabs or spaces regardless of the current indentation style, then I simply don’t understand how exactly it can be useful. Maybe I’m stupid, but could you explain it to me better?

0 Likes

#5

This setting just says “use spaces instead of tabs” to indent code. It could also be named “indent_using_spaces”, but actually it also replaces tabs in all other locations in the middle of a line and thus it is named as it is.

That’s also a good example for ST’s settings (file) hierarchie, discussed earlier.

You can specify per-user defaults for those settings in Preferences, which would be overridden by project-specific, syntax-specific or view-specific settings. With detect_indentation: true ST adjusts those settings automatically based on file content on “view-specific” level.

Those settings are useful in case you don’t like automatic indentation style/width detection. By setting detect_indentation: false ST would always use settings from Preferences. But in that case you are likely to create files with mixed indentation styles, which is terrible, IMHO.

2 Likes

#6

So is it correct to say that "detect_indentation": true overrides "translate_tabs_to_spaces"?

0 Likes

#7

Yes, that’s true.

1 Like

#8

Thanks a lot. So, to summarize, for other people who might find this thread useful:

“translate_tabs_to_spaces” controls whether to insert spaces or instead a tab when you press Tab or Command-Right Bracket. But it doesn’t force to insert them; which means that if you have “detect_indentation”: true, it doesn’t matter whether you have “translate_tabs_to_spaces”: true or false. Whether ST will insert spaces or instead a tab when you press Tab or Command-Right Bracket will depend on the detected indentation style.

0 Likes