Monday, February 14, 2011

Managing Vim Plugins with Mercurial

I always felt a little as though I was risking something each time I installed a new vim plugin. I mean, the vim plugins provide me with awesome power of customization, and my vim setup helps me work, so messing it up would be bad, and each new plugin just throws a bunch of stuff into my vim directories.

I could have tried to organize it based on the plugin name, but that always seemed like too much work.

When I read Steve Yegge's post about his dot-emacs-file, that seems cool. All his configuration files controlled by svn. However, I don't have an offsite svn repo to use.

Then I read the Joel on Software post about distributed version control and Mercurial.

I had used Mercurial before a little, but Joel's post helped me realize that I was stuck thinking about Mercurial as if it was some sort of advanced svn. It's not. I always assumed I had to have some sort of Mercurial repo that served as the 'master' copy, much the way an svn server works.

However, Mercurial is different. You can make any directory into it's own repo. This is fantastic. Now I'm using Mercurial to version control basically any test project I work on, it's fantastic. Every directory is it's own repo. If I need to move it to another computer or give it away to someone, or take some of my test projects to work, no problem. Tar it up and the whole history is there.

The next obvious step was to version control my .vim dir. Now, every time I add a new plugin, it becomes it's own commit in Mercurial. I could go back in history at any time and look at the files that were part of any plugin, or revert any change I make.

To complete the process, I moved my ~/.vimrc file into ~/.vim and renamed it myvimrc. Now, my ~/.vimrc file has only one line:

source ~/.vim/myvimrc

and .vim/myvimrc is version controlled with Mercurial.