Indent an entire file using built-in indentention engine
In command mode(Esc) enter
:gg=G to use Vim's built-in indention engine.
|gg||start of file|
|=||indent (when |
|G||end of file|
You can set
equalprg in your .vimrc to use a more sophisticated auto-formatting tool.
For example, to use
clang-format for C/C++ put the following line in your
For other file types, replace
c,cpp with the filetype you want to format and
clang-format with your preferred formatting tool for that filetype.
Indent or outdent lines
To indent our outdent the current line in normal mode press the greater than
> key or the less than
< twice accordingly.
To do the same on multiple lines just add a number beforehand
|indent current line|
|outdent current line|
|indent next 6 lines|
You can also indent using motions. Here are a few useful examples.
|indent from current line to first line in file|
|indent from current line to last line in file|
|indent previous paragraph|
|indent next paragraph|