How do I enable automatic indentation?
Answer
:set autoindent
Explanation
The autoindent option copies the indentation from the current line when starting a new line. This maintains consistent indentation while typing.
How it works
:set autoindentcopies indent from current line to new line- Pressing
o,O, or<CR>in insert mode inherits indentation - Works independently of language-specific indentation
Example
With autoindent enabled and the cursor on an indented line:
current indented line
| <- new line starts here after pressing Enter
Tips
smartindentadds one level after{and removes after}cindentprovides C-language-aware indentationfiletype indent onenables filetype-specific indentation (recommended)indentexpris the most flexible indentation method- Most users want
:filetype indent onrather than manual settings