Vim Tips Wiki
Advertisement
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
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 blocks

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

int myfunction(int a)
 {
 if ( a == 1 ) {
 printf("one");
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.

Comments

 TO DO 

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