Getting Back To VIM

I spent some time increasing my vim (vi improved) knowledge today since Ubuntu doesn’t come with a gui-based editor (like KDE’s kate) installed by default (and like weblogging software I’m always curious to try something different). I first used the venerable vi editor something like 14 years ago in an introductory Computer Science class, but I didn’t really appreciate its arrow key independance at the time. Now I wish all text editors gave you a way to move around quickly without taking your fingers off the home row. It definitely bugs me when I have to shift my right hand down to the arrow keys on my Powerbook.

Vim has some pretty nice built-in functionality, but you have to work a little bit to expose it and it definitely requires effort to get the hang of it (for a nice basic tutorial try vimtutor from the command line). On MacOS X and Ubuntu it’s basically configured in vi compatibility mode out of the box with most of the cool things like syntax highlighting turned off. It took me a while to figure out the easiest way to activate things, but it ended up being fairly simple: mv /usr/share/vim/vim62/vimrc_example.vim ~/.vimrc will copy a basic vim configuration file into your home folder that will activate vim’s cool improvements the next time you launch it.

Of course once I had syntax highlighting, auto indenting and other cool things working in vim, I immediately became irritated by the default tab spacing. Eight spaces per tab is simply too much text real estate for me, three or four is a lot more reasonable and pleasing to my eye. I turned to vim’s ample built-in help and eventually came upon a solution I was happy with, but it took me much longer than I would have preferred. Many programmers prefer their tabs to actually be written as a certain number of spaces so that code formatting remains constant across editing environments and vim has a couple different tab space settings to support this. For simplicity’s sake I prefer my tabs to be tabs and my spaces to be spaces and after quite a bit of searching I determined that required adding three more lines to the end of my .vimrc file:

set shiftwidth=3
set tabstop=3
set noexpandtab

Much nicer. With mytab issues conquered, I’m still trying to find a vim syntax coloring setup that I’m completely happy with, but I’ll save that for a later post. Stay tuned.