Different tab size depending on language


Here’s what I have in my config.cson that is working for me. Lots of stuff snipped for brevity:

    'tabLength': 4
    'tabLength': 4
    'tabLength': 4
    'showInvisibles': false
    'softWrap': true
    'tabLength': 4
    'tabLength': 4
    'fontFamily': 'SourceCodePro-Regular'
    'preferredLineLength': 100
      'cr': '↩'
      'tab': '⇥'
      'eol': ' '
    'normalizeIndentOnPaste': false
    'showInvisibles': true
    'scrollPastEnd': true

The defaults are under global and then you override things based on the scope descriptor. The path under the scope descriptor has to mirror the path under global.


Thank you, @leedohm. That was really helpful.
The problem now is figuring out if the scope name is correct or valid.

I just couldn’t get scoped php config working.
JavaScript worked perfectly!

    'tabLength': 4
    'tabLength': 4

Pretty sure this is correct though. But weirdly, it is still using my default 2 tabLength.


You can discover the correct scope by opening up the developer tools Console tab, putting your cursor in a PHP file and executing the Editor: Log Cursor Scope command. It’ll output an array of scopes to the console and the first one in the list will be the correct scope for PHP.


Wow… This is great stuff!

This was the result.

["text.html.php", "meta.embedded.block.php", "source.php"] 

PHP file without any HTML tags get text.html.php too.
Well, at least I can go back to global 2 tabLength and scope them now.
Thank you so much! :smiley:


So happy to have this built in now. Great stuff.

Language-specific soft tab size doesn't seem to work for me

Ok, the easiest way that I found was doing from package setting of languages.

Go to Preferences -> Packages and find a language package that you want to configure. For example, if you want to configure the tab length of javascript, find language-javascript and you can find Tab Length setting.


Yes, this ability has been added since this topic was last posted to :grinning:


It’s great to see this functionality added to core. Atom was unusable without it initially which led me to create https://atom.io/packages/syntax-settings. Might have to take another look at using Atom full-time!


This should also be accessible decoupled from language selection.

When switching code-styles depending on teams having the spaces hard-coded in settings is not ideal.

Instead I’ll often use Sublimes space adjustment feature in the bottom right, without this I’m left to double-tab on some projects and not on others.

(without using editorconfig)


@mryellow: If you want something similar to what Sublime Text has, check out tab-control. It provides the controls you want over tab settings. It doesn’t do “Guess Settings From Buffer” but you can get that from auto-detect-indentation. And you can get the tabs <–> spaces functionality from tabs-to-spaces.


I have a question, how to set tab size for html inside .php file?

Thanks in advance :slight_smile:


Thanks, @leedohm and @kimh. :smile:

Using @leedohm’s solution I got it to work (but by removing the quotes around editor and tabLength) for JS but not CSON as I didn’t know the descriptor for CSON.

Then tried @kimh’s solution of changing tab length for JS under settings for language-javascript package, but for some reason it kept getting changed back to the default of 4 whenever I entered the desired value of 2, so then went into the config.cson file and manually changed the tab lengths underneath the descriptors that had been created automatically from attempting to change via the package settings in Atom. Couldn’t get this to work at first but then tried again after closing Atom and it worked. I also could set a tab length for CSON (and CoffeeScript) as a descriptor for CoffeeScript had been created automatically.

Seems like a long-winded way and there are probably quicker ways that also don’t involve installing packages but I guess it’s not something I have to change very often.


Thanks @kimh. Your suggestion of going through package preferences worked perfectly. Thank you.