Sublime Forum

Set tab size for different file type?

#1

I want to set different tab size/soft tab for different language.
such as
tab size 4 for php with tab
tab size 2 for ruby with soft tab

Could I do this in sublime text?

0 Likes

Tabs in different languages
#2

I don’t know if it’s possible with ST2 out of the box, but I had a need to use a different indentation scheme for one project than I use for others. I wrote a pretty simple plugin to handle it, but it is currently directory based. I’ve been thinking about changing it to use regexps on the file name which would allow you to do what you want. I’ll try to get that converted this weekend and submitted to Package Control.

0 Likes

#3

For some reason I think that this can be done using the same kind of settings file in your User directory; something like “PHP.sublime-settings”. I haven’t tried it yet, and there’s a very good chance that I’m wrong.

0 Likes

#4

For what the OP wanted, that would be a much better solution than what I’m suggesting. If you want different indentation schemes for file types across the board, this would be the way to do it (if it works). For my case, though, I need to apply different indentation schemes across the entire project, which is why I went directory based (I tend to organize my projects by client, so this worked out well).

If anyone tries this, please let us know how it goes.

0 Likes

#5

what Grant said is the right answer.
you overwrite your base user settings in syntax specific files.
how do you know how to name the files?
you dont even need to know that.
for example let’s sat you open .php file then go to Preferences -> Settings More -> Syntax Specific User.
all settings you add there overwrite default and user settings and apply to php files.

0 Likes

#6

I have been trying to set a default tabSize for HAML files, without any luck.

I tried Grant’s suggestion, but could not get it to work. First I created a settings file in packages/User, then in packages/HAML (which I had to create), and then in packages/Rails (as the HAML language preferences are there), all without any luck.

I entered the settings in JASON format, in the file HAML.sublime-settings:

{ "tabSize" : 2,
  "translateTabsToSpaces" : true
}

I even tried naming the file “Ruby Haml.sublime-settings” as that is what is displayed as filetype in the editor window status bar.

Any ideas?

0 Likes

#7

OK, figured it out. I had the right idea, just needed to do a couple of things.

First, make sure your sublime-settings file is in the same directory as the corresponding tmPreferences file. Next, make sure to name it the same name as the tmPreferences file. Also be sure to use JASON. And, finally, the option names must be in the format “one_two_three”, not “OneTwoThree”, so “tabSize” would be “tab_size”.

Hope this helps others :smile:

0 Likes

#8

This is not true. You were probably mislead by the fact that you named the file incorrectly.
You can safely store you settings files inside Packages/User.
And to save yourself some head scratching on how to name the files and what settings are available check this:

  1. Open file of the type you’d like to customize. Then go to Preferences -> Settings More -> Syntax Specific - User. Do your magic there and save, and surprisingly the file is in fact saved in Packages/User.
    If you happen to have existing file for that language then it loads and you modify/save it.
  2. Open command pallet and type “Preferences Default”. Open the file and there lay all the settings for you to use.
0 Likes