Advanced Vim Tutorial
Vim is not just an editor. It can be an IDE if used at its best. I have found it more convenient to use than any other word processing tool i have used. With proper knowledge of the countless features provided by vim, one can be much more efficient in whatever editing job, and programming in my case.
Every time i wished for a feature, i found it there in vim. I didnt allow myself to do anything the stupid way, and always figured out a better way to do the same thing. Thats how i have got a decent expertise on vim. With this tutorial i wish to give you a feel of what all is possible with vim, and show you a direction to learn more.
Before i proceed, i would like to ask you a question. Suppose you have got a file with about 50 lines only, and you have to make few changes to the file. Lets assume that you are asked to add 10 to every number present in the file. Lets assume that there are only 25 numbers in the file and rest is text. Would you start doing it the stupid way or search for a efficient way to do it ?
Most of the times one will think that its just 25 numbers, and without thinking about a better way to do it, he just starts doing it right away. Or even if one does want to do it a better way he doesnt do it thinking that figuring out the better way will take much more time than doing it the ‘obvious way’. But what we always ignore is that its not just this time. We do it many times, and thats why it makes sense to go for the better way to do it, even if it takes more time at first time.
So next time when the thought “its just this much†comes to your mind, just remember that “its not just this time†, and the choice is yours.
If we go by Brook’s words “The tool that save the most labor in a programming project is probably a text-editing system” [The Mythical Man-Month, proposition 12.10], then we should probably work on our editing skills more than our programming skills.
In this tutorial I assume the reader to have a basic knowledge of vim. Basic features like editing, movement, searching, replacing, opening, saving etc not covered in this tutorial. I’d recommend going through vimtutor for basic understanding of vim.
Lets start.
“if its just this much, its not just this time”
–
This tutorial was prepared for my guest tutorial on March 28, 2006 for ug1 batch.
Updated May 12th, 2006 with features of vim 7.0 ( Tabs, Undo Branching and Spell Checking).
Thanks to Paresh Jain for helping me with LaTeX. Otherwise it wouldnt have been possible to write it using vim and I wasnt doing fair to it by writing it in anything else.
related -
* vim recording





March 29th, 2006 at 3:45 am
Re:
how abt having somthin like autocmd but execute it only when its a new file ?
March 29th, 2006 at 5:03 am
Whew!
13 pages… That was one long read, but totally worth it!!
March 29th, 2006 at 10:53 am
virtual ttys
it was an amazing tut. well we would like to have more next sem. but would you please post something regarding the ttys, i discussed with u last night. Thanks a lot for the tut.
March 29th, 2006 at 10:55 am
*decent expertise*
having seen smr programming firsthand on countless times and after using his .vimrc for more than 2 years (thanks for it smr), i can vouch that he has more than a “decent expertise” in vim.
guys, try his .vimrc, u’ll forget every other IDE in (pla)net.
March 29th, 2006 at 4:49 pm
Re:
Where do we obtain his .vimrc?
March 30th, 2006 at 6:20 am
Re:
How come your not a fan of emacs ?
March 30th, 2006 at 6:45 am
Re:
From the tutorial:
Another equally good editor. GNU & RMS product. Lisp based. show help on show more help on
Emacs vs Vim
its your call.
But let the reason be more than geekyness and blind support
of GNU.
Bottom line If unlike me you ï¬nd Ctrl-X Alt-Y Shift-Z natural
way of editing, there is no reason you shouldnt use it.
Emacs Tutorial
Ctrl-h t emacs turorial. Good enough to get you started.
Ctrl-x u/Ctrl-/ undo
Ctrl-s search
Ctrl-h c
Ctrl-h k
Ctrl-h f describe a function
Ctrl-h a show command apropos
Ctrl-x 1 close all windows but active
Alt-x execute a command by its name
Ctrl-g quit current command. Return to normal mode.
Ctrl-x Ctrl-c quit emacs
March 31st, 2006 at 9:13 am
Look at the following links:-
http://www.rayninfo.co.uk/vimtips.html
http://www.moolenaar.net/habits.html
Though I must agree that I have slowly started liking emacs