Currently pressing TAB in evil insert mode, runs indent-for-tab-command

I'm not sure of the exact details, but from what I can tell this is performing some kind of re-indentation, which does nothing if emacs consideres the text already indented.

I would like this to behave (like vim) where.

  • When tabs are enabled a \t is inserted *.
  • When tabs are disabled, insert n spaces, aligning to the tab-width.

Is this possible?

* by tabs enabled I mean (setq indent-tabs-mode t).

  • 2
    Why not embrace Emacs and its smart indentation? Each mode is free to set it to something smarter than indent-relative and this makes for less tab key usage if it's configured properly. You can do the same by overriding the indentation function for modes that don't behave.
    – wasamasa
    Commented Oct 17, 2016 at 6:26
  • ^ this. Also, you might want to check this article out by Xah Lee Commented Oct 17, 2016 at 6:33
  • 1
    @wasamasa: Vim/Evil have the = operator for that.
    – Nova
    Commented Jan 10, 2017 at 4:33
  • @wasamasa re: Why not embrace Emacs and its smart indentation? - when working on larger projects not everyone uses Emacs. There might be external formatting utilities such as clang format, yet - that can be disabled for blocks of code too... in short, sometimes I just want to insert tab aligned indentation without relying on Emacs to do what I want.
    – ideasman42
    Commented Aug 4, 2021 at 6:03

1 Answer 1


To have tab work as it does in VIM, use tab-to-tab-stop.

(define-key evil-insert-state-map (kbd "TAB") 'tab-to-tab-stop)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.