Sunday, July 20, 2008

Customizing VIM

For the first time in a long time, I spent my weekend not working on something directly related to my job. I decided that it's time that I really got myself to learn VI. I've been using the basics of VI forever and when it came to serious code editing in a terminal, I tend to fall back to EMACS. In a GUI environment, my favorite editor is Visual Slickedit but right now I don't have it for OSX and our servers don't have it or EMACS installed.

So the first thing I did was try to make VIM a comfortable environment for me to work in. The default black text on white background didn't work for me so I changed the terminal to black-on-white. Of course, this re-introduced another of those annoyance that always got under my skin. Who the hell chose a dark blue font color for directories?!? Who can actually read that without going blind after 2 minutes? So, of course, that has to change... Out comes the editor and changing the LS_COLORS environment variable.... but wait... OSX doesn't use that name. It uses LSCOLORS instead... Those wacky BSD guys. Okay, no problem. Let's see export LSCOLORS='di=...'...
Uh, wait, that doesn't work 'cause that just makes things too easy to understand. Instead, how about:

export LSCOLORS='fxFxcxdxbxegedabagacad'

Uh...yeah... that's intuitive. Assembly programmers, I respect. Whoever came up with this is an idiot.

My linux version is a bit more customized:

export LS_COLORS="no=00:fi=00:di=36:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=
01;32:*.btm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:
*.bz2=01;31:*.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:"


Okay, now it was time to get to know VIM and all its goodies such code folding, color syntax, debugging, intellisense (or it's new name: omnicomplete), etc. Being the lazy hacker that I am, I first looked around to see what other people already did so I can borrow their stuff. I came across Andrei Zmievski's presentation and he included his VIM scripts which did pretty much everything I wanted. Sweet!

So, putting on my RHEL5 workstation and OSX machine had no problems. The problem is that I'm also doing a lot of work on RHEL4 machine which only has VIM 6.3 and a lot of the plug-ins don't work. I had to download the source from vim.org and compile it myself. Since I wanted the ability to work with xdebug, I had to tell the build to include those features. After compressing the source, you can run:

./configure --help

to see all the different options. Basically, I needed to do this:

./configure --enable-pythoninterp --with-python-config-dir=/usr/lib/python2.3/config

(Look at the output from config to make sure it found the python config. If not, download and install the python_dev package.)

Then run make and it compiled.

In the end, it was fun to learn something new. I learned a lot more about VIM such as color schemes, plug-ins, etc., and now I have a comfortable environment to work in even without EMACS.

No comments:

Post a Comment