how to auto-indent in emacs
February 8th, 2006 by Lawrence David
one of the reasons why i use emacs, as opposed to just a vanilla text editor, is that it auto-indents your code. all you’ve got to do is ask it to do so nicely.
just highlight the region of code you want indented (control-space at the beginning of the text block, then move the blinking cursor to the end of the text block) and hit:
>> C-M-\
or, “control-meta-backslash.”
Not always working, maybe i’m dull on this …
Ctrl+M just gives a newline, before hitting \
It’s not control + M (as in shift+m) it’s control + meta, usually alt or escape. So, depending on your settings it might be control+alt+\
thank you
and thank you emacs so nice this auto indent
You’re confusing auto-indent with auto code formatting. auto-indent means that it inserts the same space before a new line as it did on the previous line.
Automatic code formatter is a different thing entirely. Ctrl+Alt+\ is an auto code formatter. Your article caused me hours of confusion before I found out what the VI equivalent of :set ai was on emacs….
And could you write what is the VI equivalent od :set ai in emacs?
Thanks a lot !
I used to hit tabs per line before. This is awesome. Is there a way to remove multiple blank lines and keep only one blank line ?
Thank you for the tip! Quite useful. If indent-tabs-mode is nil, will tabs be converted to spaces?
Works great! thanks for the tip.