Indent several lines in Emacs

[Warning: This approach might lead to errors as mentioned in one of the comments. Iniviting suggestions to fix it.]

Steps to do indentation interactively.

  1. Select the region to be indented.
  2. C-x TAB.
  3. Use arrows (← and →) to indent interactively.
  4. Press Esc three times when you are done with the required indentation.

Select multiply lines, then type C-u 8 C-x Tab, it will indent the region by 8 spaces.

C-u -4 C-x Tab will un-indent by 4 spaces


If you want Emacs to correctly indent multiple lines, then the command is C-META \ also known as C-M-\. In other words, it's not Control - M, but Control - Meta - Backslash (Control + Alt + \ on most keyboards)