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:

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!

7 thoughts on “Maintaining an up-to-date Vim configuration with git submodules

  1. Hi, I have been attempting to do this for a while. I add everything like describe above, but on a new machine I do a git clone. And make sure I have a .vimrc file in my home directory. But all of installed submodules will not work out of the box on a new machine. Is there something I need to run after I clone my repo?

    Thanks for any help you could shine on this.

    Loran

  2. When cloning a git repository, by default its submodules are not fetched.
    You can fetch any updates on the submodules by running git submodule update --init.
    Or clone the repo with the --recursive option initially: git clone --recursive git://...

  3. Nevermind, I switched to Vundle. The problem I had was I was not compiling Command-T with the correct version of ruby. For others who stumble across it: Compare the output of `ruby -v` with `vim –version | ruby` and use rvm to switch to the right version and run make inside the Command-T directory.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>