Vim Indent Object Plugin


I recently moved to Vim from Sublime Text 2. I love Vim and been slowly converting all the usual ways of doing things in Sublime Text 2 into the Vim way. I’ve converted almost all my shortcuts except one, expand selection to indentation. This is incredibly useful for reindenting malformed lines or changing entire code bodies. After a lot of looking I finally found Vims equivalent vim-indent-object.

public function update(time:Int) {
    if(someCondition){
        input.update(time);
        graph.update(time); <---
        var value:Int = 10;
    }
}

Say your cursor is at that arrow, how would you change everything inside the if statement? With vim-indent-object you can just type cii, this will [c]hange [i]nside the [i]ndentation.

public function update(time:Int) {
    var foo:String = "test";
    var lala:Int = 10;

            this.codeBlock();
            this.pastedText = ""; <---
            var newCode:Int = 40;
}

An other example, say you just pasted some code and it is horribly indented. You can fix the indentation with =ii.

public function foo() {
    var tileMap = [
        [0, 0, 0, 0],
        [0, 0, 0, 0], <---
        [0, 0, 0, 0]
    ];
}

With vim-indent-object you can easily delete objects spanning over multiple lines. The tileMap variable can be deleted by typing daI, delete indentation including the top (a) and bottom (I). You can just remove the top by typing dai.

Unforunately the plugin looks inactive with the last commit in March 2011. It’s still a great plugin and I think every give it a try.

Related Posts

Test Your Chinese Using This Quiz

Using Sidekiq Iteration and Unique Jobs

Using Radicale with Gnome Calendar

Why I Regret Switching from Jekyll to Middleman for My Blog

Pick Random Item Based on Probability

Quickest Way to Incorporate in Ontario

Creating Chinese Study Decks

Generating Better Random Numbers

Image Magick Tricks

My Game Dev Process