Vim – indentation tip

April 9th, 2007

I've been using Vim for a long time but up to this day I had no idea about one of its greatest features.
Suppose we have an unindented c/c++ code like this one:

C++:
  1. {
  2.     if(sth != NULL)
  3.     {
  4.     foo();
  5.         bar();
  6. foo();
  7. }
  8. }

and we want to have it indented like this one:

C++:
  1. {
  2.     if(sth != NULL)
  3.     {
  4.         foo();
  5.         bar();
  6.         foo();
  7.     }
  8. }

All we have to do is to put a curson on a first opening bracket and type =% in normal mode.

PRICELESS!

Leave a Reply

Designed by SirMike © All rights reserved

Valid XHTML 1.0! Valid CSS!

Powered by Rootnode