Home Download Buy Blog Forum Support

set tab size for different file type?

set tab size for different file type?

Postby kenziii on Wed Aug 08, 2012 11:20 pm

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?
kenziii
 
Posts: 6
Joined: Wed May 04, 2011 1:27 am
Location: Sydney

Re: set tab size for different file type?

Postby phillip.koebbe on Wed Aug 08, 2012 11:47 pm

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.
-- Phillip

Code: Select all
while self.living? do
    mistake = Mistake.new
    self.learn_from!(mistake) unless mistake.fatal?
end
phillip.koebbe
 
Posts: 208
Joined: Tue Dec 20, 2011 4:58 pm

Re: set tab size for different file type?

Postby Grant on Thu Aug 09, 2012 11:58 am

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.
Grant
 
Posts: 68
Joined: Fri Jan 20, 2012 2:42 pm

Re: set tab size for different file type?

Postby phillip.koebbe on Thu Aug 09, 2012 1:33 pm

Grant wrote: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.


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.
-- Phillip

Code: Select all
while self.living? do
    mistake = Mistake.new
    self.learn_from!(mistake) unless mistake.fatal?
end
phillip.koebbe
 
Posts: 208
Joined: Tue Dec 20, 2011 4:58 pm

Re: set tab size for different file type?

Postby vitaLee on Thu Aug 09, 2012 1:57 pm

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.
vitaLee
 
Posts: 150
Joined: Tue Dec 27, 2011 11:10 pm

Re: set tab size for different file type?

Postby gushot on Wed Nov 21, 2012 9:48 pm

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:

Code: Select all
{ "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?
gushot
 
Posts: 6
Joined: Wed Aug 01, 2012 12:25 am

Re: set tab size for different file type?

Postby gushot on Wed Nov 21, 2012 10:01 pm

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 :)
gushot
 
Posts: 6
Joined: Wed Aug 01, 2012 12:25 am

Re: set tab size for different file type?

Postby vitaLee on Wed Nov 21, 2012 10:17 pm

First, make sure your sublime-settings file is in the same directory as the corresponding tmPreferences file.

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.
vitaLee
 
Posts: 150
Joined: Tue Dec 27, 2011 11:10 pm


Return to General Discussion

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 10 guests