vimtricks.wiki Concise Vim tricks, one at a time.

How do I auto-indent the current line?

Answer

==

Explanation

The == command auto-indents the current line based on the surrounding context. It uses Vim's built-in indentation rules for the current filetype.

How it works

  • == adjusts the indentation of the current line
  • Uses the indentexpr or built-in C-style indenting
  • Works based on the file type and syntax

Example

if (true) {
return 1;
}

With the cursor on return 1;, pressing == indents it:

if (true) {
    return 1;
}

Tips

  • =G auto-indents from the current line to end of file
  • gg=G auto-indents the entire file
  • =ap auto-indents the current paragraph
  • 3== auto-indents 3 lines
  • In visual mode, = auto-indents the selection

Next

How do you yank a single word into a named register?