Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to make emacs insert either 4 spaces or a tab when I press the tab key. Nothing else. I don't want smart indentation, I don't want it to auto-align itself or try to do anything smart. I just want it to output 4 spaces (or a tab). =

share|improve this question
up vote 2 down vote accepted

The problem is that each mode in emacs defines the TAB key diferently. To get a global behavior, look at Trey Jackson's answer in

 (defvar just-tab-keymap (make-sparse-keymap) "Keymap for just-tab-mode")
 (define-minor-mode just-tab-mode
   "Just want the TAB key to be a TAB"
   :global t :lighter " TAB" :init-value 0 :keymap just-tab-keymap
   (define-key just-tab-keymap (kbd "TAB") 'indent-for-tab-command))

You may want to use 'self-insert-command instead of 'indent-for-tab-command as pointed out by another person answering the question.

share|improve this answer
Thanks, much appreciated. – Chris Apr 8 '11 at 17:08

Try this.

Find your .emacs and add this:

(setq c-basic-offset 2)

this make your emacs inserts 2 spaces, you can change the number and put 4,

(setq-default indent-tabs-mode nil)

if you want spaces NO tabs

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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