Vim Tips Wiki

Indent a code block

1,624pages on
this wiki
Add New Page
Talk0 Share
Tip 597 Printable Monobook Previous Next

created 2003 · complexity intermediate · author Marcel Preda · version 6.0

This tip contains information about adjusting the indent of source code in a block formed by braces ({...}), such as is used in the C language.

For related information, see:

Commands to indent blocksEdit

Suppose the indent options are correctly defined and we find this badly indented code:

int myfunction(int a)
 if ( a == 1 ) {
return 1;        // the cursor is in this line
 return 0;

These commands will fix the indents:

  • =i{ reindents "inner block" (inside the braces).
  • =a{ reindents "a block" (including the braces).
  • =2a{ reindents 2 blocks (this block and containing block).

Instead of "{", you can use "}" or "B", for example, =aB indents a block.

These commands will decrease or increase indents:

  • >i{ increase indent for inner block.
  • . repeat last change (increase indent of block again).
  • <i{ decrease indent for inner block.

With the cursor on { or }:

  • =% indents the block (including matching brace).
  • >% or <% indents or unindents the block.



  • Check advice.
  • Perhaps add more vaB, viB, >aB, >iB.

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random Wiki