Emacs: Indentation/Completion Commands
Here's how to indent code.
Indent Current Line
Indent a Text Selection
Select a region, then
More indent commands:
- Indent current line in the same style as previous non-blank line.
indent-relativeindent current line like previous non-blank line, only if the previous line has more indent than current line.
- Indent all lines in a region, right or left.
Force Insert Tab Character
The following method works everywhere (also works in minibuffer).
To insert a literal tab char, press Ctrl+q Tab.
To insert a newline char, type Ctrl+q Ctrl+j.
You need to use the above method to insert these characters, because for example in minibuffer, pressing Tab does name completion and pressing Enter finishes the prompt. In most programing language modes, pressing Enter or Tab also does some auto indenting.
[see Emacs: Newline Representation ^M ^J ^L]
Convert Tabs to Space in Source Code
Select a region first, then Alt+x
to change spaces to tabs.
Make Whitespace Visible
Emacs: Make Whitespaces Visible
Emacs: Name Completion
Emacs: Tab/Space/Indent Setup