Next: , Up: Indentation

24.1 Indentation Commands

Apart from the <TAB> (indent-for-tab-command) command, Emacs provides a variety of commands to perform indentation in other ways.

C-j
Perform <RET> followed by <TAB> (newline-and-indent).
C-M-o
Split the current line at point (split-line). The text on the line after point becomes a new line, indented to the same column where point is located. This command first moves point forward over any spaces and tabs. Afterward, point is positioned before the inserted newline.


M-m
Move (forward or back) to the first non-whitespace character on the current line (back-to-indentation). If there are no non-whitespace characters on the line, move to the end of the line.
M-i
Indent whitespace at point, up to the next tab stop (tab-to-tab-stop). See Tab Stops.


M-x indent-relative
Insert whitespace at point, until point is aligned with the first non-whitespace character on the previous line (actually, the last non-blank line). If point is already farther right than that, run tab-to-tab-stop instead—unless called with a numeric argument, in which case do nothing.
M-^
Merge the previous and the current line (delete-indentation). This “joins” the two lines cleanly, by replacing any indentation at the front of the current line, together with the line boundary, with a single space.

As a special case (useful for Lisp code), the single space is omitted if the characters to be joined are consecutive opening and closing parentheses, or if the junction follows another newline.

If there is a fill prefix, M-^ deletes the fill prefix if it appears after the newline that is deleted. See Fill Prefix.

C-M-\
Indent all the lines in the region, as though you had typed <TAB> at the beginning of each line (indent-region).

If a numeric argument is supplied, indent every line in the region to that column number.

C-x <TAB>
Shift each line in the region by a fixed distance, to the right or left (indent-rigidly). The distance to move is determined by the numeric argument (positive to move rightward, negative to move leftward).

This command can be used to remove all indentation from the lines in the region, by invoking it with a large negative argument, e.g., C-u -1000 C-x <TAB>.