Alex Gyoshev

Maintaining an Up-to-date Vim Configuration With Git Submodules

[Update: The Vundle plug-in conveniently abstracts away the approach described here. I have been using it for quite a while and highly recommend it, just as Erik did]

Nowadays, people share even their DNA on GitHub. With such a healthy open-source ecosystem and new updates every day, here is a way to keep up with the latest versions of your vim plug-ins.

Git submodules

Let’s start with an idea – consider your vim configuration as project, with plug-ins as dependencies. Since you want to have the latest and greatest, you may want to directly link to their sources on github. But how? This is where git submodules come in:

<code title="git submodule basic syntax">git submodule add <repository> [<path>] </code>

In the case of your vim configuration, the above command will take the following form:

<code title="cloning the NerdTree plug-in to your vim bundle">git submodule add https://github.com/scrooloose/nerdtree.git .vim/bundle/nerdtree</code>

The above command will add a reference to the project located at to your vim configuration (that is itself in git). However, there is a problem: due to the fact that many projects have their own directory structure, you cannot just add them easily to the specific directories that vim expects. Luckily, vim superstar Tim Pope has developed a remedy called “pathogen”.

Pathogen

This great plug-in will load other plug-ins from the ~/.vim/bundle directory. Since pathogen is yet another dependency of the project, it should be placed in the .vim/bundle folder:

<code title="cloning the NerdTree plug-in to your git bundle">git submodule add https://github.com/tpope/vim-pathogen.git .vim/bundle/pathogen</code>




<code title="pathogen initialization">source ~/.vim/bundle/pathogen/autoload/pathogen.vim
call pathogen#infect()</code>

Now that vim is infected with the pathogen, your modules are fully loaded. Hack away!

Updating plug-ins

Here comes the really sweet part: if you want to update all your plug-ins (bound by submodules), it is as sexy as running one line in bash:

<code title="updating all git submodules (i.e. vim plug-ins)">git submodule foreach git pull origin master </code>

Updating a single module is done by a git pull origin master, if you ever need to.

In conclusion

I hope that this will let you manage your vim configuration with ease – it works great for me! We are one step closer to our personal configuration heaven. If you found this article to be useful, leave a comment or hit me up on twitter!

Comments