Saturday, December 6, 2008

making vi friendlier on Ubuntu

In the world of computing, there is no holy war that has been waged longer or fiercer than the editor war. The mere mention of vi or emacs in a tech forum post is the beginning of the end for that thread, and innocent bystanders should get out of the way as soon as possible. It has always occurred to me though, that there is one group of people, the young and uninitiated, for whom this endless battle is a but a strange curiosity. I know this because I was once a member of this group. Reading through the vicious flame wars, I became convinced that there was literally no decision more important than choosing your text editor, and these two (vi and emacs) were without question the only two worth choosing from. They were more than software, they were a marker of one's identity. To choose one was to align yourself with an ideology, and it was a choice with far deeper ramification than pc or mac could ever have. One could imagine my shock then, when I sat down at my Linux machine and started up vi for the first time. I stared at the cursor as it steadily blinked on the spartan background of the terminal. I squinted my eyes at the long list of arcane commands I found in a reference book. Once I got up the courage, I tried typing in some Java code...

No syntax highlighting.

No automatic code indention.

Nothing. I might as well be using notepad.

If you are a recent Linux convert, and a programmer, you too may have experienced the exact same thing. The good news is, you can believe the hype, vi is the amazing tool you have heard it is. The bad news is, it doesn't just come that way, and it's not terribly obvious how to get it that way. Hoperfully, however, I can help a little. I'm guessing the first thigns you want are syntax highlighting automatic code indention. These can be added fairly easily (note: I am assuming you are using Ubuntu, these instructions may not work on another distribution). The first issue here that confuses most people is that Ubuntu does not come with the full vi package by defualt, but rather vim-tiny (also note: vi is pretty old school and is generally not used much these days. Instead an updated version called vim is used, but it is often still referred to as vi, and starting vi at the command line will start vim instead). Once you have the package installed you just need to copy the code in an example file that comes with it over into the .vimrc file in your home folder. This will take care of the aforementioned issues. The commands you need to enter are:

sudo apt-get install vim-full
cp /usr/share/vim/vim71/vimrc_example.vim ~/.vimrc

Aftere you do this fire up a shell and try it out. I have tested it so far with C/C++, Java, and Python code and it works great for all three. I hope this helps get you up and running with vi, and I will try to post more fun tips as I come across them.

No comments: