Archive for the ‘Vim’ Category

Reindenting a File in Vim

Friday, December 7th, 2007

I’m going to post a series of helpful Vim snippets here, particularly for features that I don’t necessarily use every day and hence forget about after a while. By posting them here, I’ve got a nice easy one-stop-shop for finding them.

The first tip is reindenting source code. Hitting ‘=‘ will reindent visually-selected code , or you can also use a motion to constrain the affected area. ‘gg=G‘ will reindent the entire file:

using System;

namespace IndentExample
{
public class Indent
{
public static void Main(string[] args)
{
Console.WriteLine("badgerbadgerbadger");
}
}
}

to

using System;

namespace IndentExample
{
    public class Indent
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("badgerbadgerbadger");
        }
    }
}

More info: http://www.vim.org/tips/tip.php?tip_id=83