Having a hard time with soft tabs?


A quick google search on hard and soft tabs in Atom shows that lots of people have trouble with this issue, and that a lot of the recommended solutions seem to work for some people but not others. After struggling with the settings for a while today, I think I can explain what’s going on to others who might be having trouble getting the result they want, without having to try installing 6 different packages (or any).

The problem seems to be that Atom has two different internal properties that affect tabbing: softTabs and tabType.

Setting softTabs might not work if tabType is for some reason contradicting it (for example because you’re new to Atom, and, like me, you just tried a bunch of random things without understanding them first).

softTabs takes a boolean (true or false)
tabType takes an argument, either 'soft', 'hard', or 'auto'

These settings can be accessed and changed in the config.cson file.

That’s enough info if you always want to use the same type of tab, but if you want to use different tab types for different languages, read on…

For most users, I would recommend ALWAYS having tabType set to 'auto'. This allows you to specify the type of tab for each file, or type of file, using softTabs.

You can do this by adding the following line to config.cson:
     tabType: 'auto'
under the heading:

Then you can set softTabs to whatever your normal preference is:
     softTabs: true
and change it in each file using the Toggle Soft Tabs command, available for example with Cmd+Shift+P.

This is huge pain, so you might want to use the magical init.coffee file to set preferences for different types of files. The following code, inserted into init.coffee, will set the tabbing preference based on the file extension. This code will turn off softTabs for ‘.abc’ files and on for ‘.cba’ files:
path = require 'path'
atom.workspace.observeTextEditors (editor) ->
     filepath = editor.getPath()
     if path.extname(filepath) is '.abc'
     if path.extname(filepath) is '.cba'

Tab sizes can be changed with similar code:

If you try all this and is doesn’t work:

  1. Save everything
  2. Close Atom
  3. Test the settings by creating a new file

Hope this helps someone avoid spending as much time as I did figuring it out.