What's the simplest way to set up auto indentation in Emacs? I can see that auto-fill correctly wraps, say:

  This is an indented block, and the
  wrapping happens as expected.

On the other hand, I get this unwanted behavior:

  This is an indented short line.
I'm now taken to the beginning of the
line.  I expected to be under the "T".

In other words, how can I get the equivalent of vi's se ai in Emacs?

  • 2
  • 1
    it is mode dependant. What type of file do you want indented? Each mode will typically have its own indent variables. One might also want to address tabs vs. spaces. – bsd Jul 13 '14 at 9:25
  • jordanm, your link does it for me (I'm disappointed at the verbosity required if you don't want to press C-J instead of RET...). Feel free to leave an answer so I can accept it. – ezequiel-garzon Jul 13 '14 at 13:35
  • Thanks, bdowning. I was hoping for something even in fundamental mode. – ezequiel-garzon Jul 13 '14 at 13:36

Posting comments as an answer so this question has a formal answer...

The short answer is that for a buffer in "fundamental mode", run M-x electric-indent-mode

Emacs is modal, and each mode selects the kind of auto-indentation that is appropriate for that mode. For example, if you edit a text file, you will be in "text mode" and lines will by default automatically respect indentation of a prior line.

When Emacs doesn't find a special a mode for the buffer you are editing, it defaults to something called "Fundamental Mode". The document string for this is:

Major mode not specialized for anything in particular.
Other major modes are defined by comparison with this one.

The way many modes handle auto-indentation is to use a minor mode called "electic-indent-mode" (A minor mode is a variation added to a major mode like "fundamental mode").

Finally, as indicated in the comments, Emacs Wiki has more information on indentation.

  • Thanks! It's been indeed a while since I asked the question, and you have provided a solid and thorough answer. Cheers. – ezequiel-garzon Oct 25 '15 at 0:03

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.