Sublime Forum

How do I set language specific settings for my tab key

#1

Though I’ve used sublime on and off for a few years, I’m still a bit of a newbie in it.

One thing that I can’t figure out is how to set language specific settings.

In particular I need at times to have my tab key tab to the next mod 2, 4, or 8 tab stop using spaces, or to enter a real tab character, depending on which language I’m in. For example Makefiles and shell here documents can require a real tab character, Nim prohibits them, and C and Python varies, by project and/or user preference, but in Python tab characters must be equivalent to mod 8 tab stops, whereas for Nim it should probably be mod 2 tab stops (all give or take some details and my imperfect recollections.)

I presume that I can configure Sublime to automatically guess which flavor I want based on the filename suffix.

I don’t see how to do anything like that, however.

I am using Sublime build 3114.

My Preferences menu hierarchy includes:

  • Settings Default
  • Settings User
  • Settings More ==> Syntax Specific, Distraction Free
  • Key Bindings Default
  • Key Bindings User

Thanks !

1 Like

#2

Settings More -> Syntax Specific will open/create a settings file for the current syntax highlighting used in your current tab. Here you can set your tab size/spaces preferences.

As for inserting a literal tab in some situations, you may need to adjust your keybindings or use shift+tab

2 Likes

#3

[quote=“kingkeith, post:2, topic:22971, full:true”]
Settings More -> Syntax Specific will open/create a settings file for the current syntax highlighting used in your current tab. Here you can set your tab size/spaces preferences.[/quote]
Ah - the key is that there’s a search path for settings files, from the default settings in the distribution, to the user’s overrides, to the user’s syntax (per programming language) specific overrides.

For example, I could place my specific overrides for the Python files that I edit in the file:

~/.config/sublime-text-3/Packages/User/Python.sublime-settings

For example, when I open up a *.py Python file to edit in sublime3, the Sublime menu option “Preferernces” ==> “Settings - Syntax Specific” opens up two files:

~/.config/sublime-text-3/Packages/Default/Preferences.sublime-settings

and

~/.config/sublime-text-3/Packages/User/Python.sublime-settings

The second of these two files doesn’t actually exist on my disk yet, so just a stub contents is provided.

The first of these two has the the default distributed settings, and this useful comment at the top:

// Place your settings in the file "Packages/User/Preferences.sublime-settings",
// which overrides the settings in here.
//
// Settings may also be placed in syntax-specific setting files, for
// example, in Packages/User/Python.sublime-settings for python files.

So I could override the default distributed settings for all syntaxes using the file:

~/.config/sublime-text-3/Packages/User/Preferences.sublime-settings

and as stated above, I could override the Python specific settings using the file:

~/.config/sublime-text-3/Packages/User/Python.sublime-settings

===

I wrote the above because (1) I remember stuff better if I write t, (2) it might be useful to someone else, and (3) in case I got it wrong, I might get lucky and have someone point out my error to me.

Thanks!

2 Likes

#4

correct :slight_smile: see also http://sublime-text-unofficial-documentation.readthedocs.io/en/latest/customization/settings.html

1 Like