Updating Vim to Use Plugins From Branches

I decided the other evening that I should refresh my vim plugins to pick up any updates that have landed since the last time I updated them. The downside is that every time I want to do this, I have the pain of manually re-installing the updated files into the various plugin directories to get the plugins updated. This is far from ideal, so this time I decided to do something about it. First I stripped out all of the old plugins from ~/.vim/plugins and made a list of the plugin repos on github.

Pathogen

pathogen is a helper for modifying the runtimepath. This makes it possible to branch a plugin from github to .vim/bundle and then pathogen will ensure that it's added to the runtime path.

To make this work first you need to download pathogen and place it in .vim/autoload

Next add the following to your .vimrc file:

call pathogen#runtime_append_all_bundles()

Once you have done this simple check-out the branches of your favorite vim plugins to .vim/bundle and that's it.

Scripting plugin updates

To make life even easier I knocked up a very crude python script and Makefile to clone all my favorite plugins when I run "make get" and update them when I run "make update".

It's crude because currently it only cares about git (currently all the plugins I care about are on github) and it doesn't currently allow revs to be specified. Though both of these features could be fairly easily added. Anyway, in-case it's useful as a starting point to for someone else, here's the script:

Also if you're using git to version your branch (I'm not). Then you could use git submodules to achieve a similar effect.

#!/usr/bin/env python

import os
import sys
import subprocess

BUNDLE_DIR = os.path.expanduser("~/.vim/bundle")

plugin_branches = {
    "git": [
        "git://github.com/tomtom/tlib_vim.git",
        "git://github.com/garbas/vim-snipmate.git",
        "git://github.com/scrooloose/nerdtree.git",
        "git://github.com/scrooloose/syntastic.git",
        "git://github.com/MarcWeber/vim-addon-mw-utils.git",
        "git://github.com/scrooloose/nerdcommenter.git",
    ],
}

def get():
    os.chdir(BUNDLE_DIR)
    for vcs_type, branches in plugin_branches.items():
        if vcs_type == "git":
            for branch in branches:
                subprocess.call(["git", "clone", branch])

def update():
    os.chdir(BUNDLE_DIR)
    for vcs_type, branches in plugin_branches.items():
        if vcs_type == "git":
            for branch in branches:
                subdir = os.path.split(branch)[-1][:-4]
                os.chdir(subdir)
                subprocess.call(["git", "pull"])
                os.chdir("../")
                
if __name__ == "__main__":
    args = sys.argv
    if args and len(args) > 1:
        if args[1] == "get":
            sys.exit(get())
        elif args[1] == "update":
            sys.exit(update())

If you save this somewhere as deps.py you can then run it as python deps.py get and python deps.py update. I use a simple Makefile to do this.

The code is deliberately structured to make it easy to modify if you wanted to add mercurial or bzr support. That is left as an excercise for the reader.

It's likely I will update this script in due course, to keep up to date with that and any other aspects of my vim conf you can get the whole thing from here: lp:~muffinresearch/+junk/dotvim

Show Comments