I'm fairly new to aquamacs/emacs and while editing I noticed that it indents however it wants. In order to indent the way I want I end up using M-i, but that is pretty cumbersome. So, how do I make the TAB key behave like M-i (that is, inserting 4 spaces whenever I press it, regardless of the type of file I am editing)?

  • 2
    Basically, you want to bind the command that M-i calls to the tab key. You can check what command that is with C-h k M-i (describe-key). You can also have a look at how to bind keys in the Emacs manual and on Xah Lee's tutorial. Just a heads-up, though: a lot of packages and libraries make extensive use of the tab key for things other than indentation, so you may not want to overwrite those bindings.
    – Dan
    Jan 9 '15 at 22:43

You can find out the command that is executed by M-i,

C-h k M-i

and bind it to TAB:

(global-set-key (kbd "TAB") #'tab-to-tab-stop)

However, this will set the global binding, while you are most likely concerned with the binding of one or more global modes:

(add-hook c-mode-common-hook #'(lambda () (local-set-key (kbd "TAB" #'tab-to-tab-stop))))

But perhaps it would be better if you could describe what are your issues with Emacs' indentation (in a different question), so we can help you solve that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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