Is there a tab setting in Atom that preserves the indentation string?


Atom is gaining support for several languages that I work with and so far I like it a lot, but there is one thing that is driving me to distraction. I can’t figure out how to configure it so that auto indent preserves the indentation string from the previous line, like Vim’s “copyindent”, rather than changing tabs to spaces (soft tabs) or spaces to tabs (hard tabs).

I work with indentation-sensitive languages and use tabs semantically, for scope, and spaces non-semantically, for alignment. So long as the tabs precede the spaces at the start of a line this works fine regardless of the tab stop settings – I believe people call this “smart tabs”. Anyway, all I want is for Atom to preserve my indentation string as I type it and not convert my tabs to spaces or vice-versa. Is this possible?


If you’re looking for what you can do right now in Atom, you want to find the “Tab Type” setting in the Editor settings in Settings View:

You want to set it to “auto”. But it will look at the beginning of the file, not the line directly previous.

If you’re looking for smart tabs specifically, then the discussion topic for that is here:


@EdwardMorehouse Here is some scaffolding, I hope it helps. If you have show invisibles enabled… you might want to disable it. I found that setImmendiate was faster than nextTick at the bottom.

atom.workspace.observeTextEditors (editor) ->
   process.nextTick () ->
      editor.element.addEventListener 'keydown', (event) -> copyIndent(event, editor)

copyIndent = (event, editor) ->
   return unless event.keyCode == 9

   previousLine = editor.lineTextForBufferRow(editor.getCursorBufferPosition()[0] - 1)
   # OR
   previousNonBlankLine = editor.lineTextForBufferRow(editor.buffer.previousNonBlankRow(editor.getCursorBufferPosition()[0]))

   # your comprehension here
   tab = '...'


   # hax
   preventDefault = editor.createCheckpoint()
   window.setImmediate () -> editor.revertToCheckpoint(preventDefault)