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++:
{
    if(sth != NULL)
    {
    foo();
        bar();
foo();
}
}

and we want to have it indented like this one:

C++:
{
    if(sth != NULL)
    {
        foo();
        bar();
        foo();
    }
}

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!