Maintaining an up-to-date Vim configuration with git submodules
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:
git submodule add <repository> [<path>]
In the case of your vim configuration, the above command will take the following form:
git submodule add https://github.com/scrooloose/nerdtree.git .vim/bundle/nerdtree
The above command will add a reference to the project located at <repository> 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:
git submodule add https://github.com/tpope/vim-pathogen.git .vim/bundle/pathogen
source ~/.vim/bundle/pathogen/autoload/pathogen.vim
call pathogen#infect()
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:
git submodule foreach git pull origin master
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!
Erik
August 22, 2011
1:07 pm
Nice post,
Checkout Vundle as well (https://github.com/gmarik/vundle) really simple..
gyoshev
August 22, 2011
2:35 pm
Looks very promising, thanks!
Finn Fitzsimons
February 18, 2012
7:17 pm
Hi there gyoshev.
I am looking for a web developer living in Sofia to help me to redevelop my website numberpicture.com. Please can you mail me if you might be available to do so.
cheers