Friday, February 10, 2012

Multi-diff with Vim and Git

I just pushed some stuff to github that you may find useful if you're either a git user, a vim user, or (best of all) both.


For git users, there's git-multidiff, which works kind of like git difftool, except that it invokes your tool of choice once on the entire set of files, instead of once for each pair. This is handy if you have a diff tool that'll let you view multiple diffs simultaneously.

Full installation instructions are in a comment at the top of the file, but it basically consists of putting git-multidiff and _git-multidiff-helper in your path and adding an entry to your .gitconfig. Note that it requires Python (I've tested it with 2.7.2).


Speaking of “diff tools that'll let you view multiple diffs simultaneously”, that's what tab-multi-diff.vim is for. It lets you do a “vimdiff” on multiple pairs of files, with each pair in a separate tab.

To install it, just save tab-multi-diff.vim in your vim plugins directory (typically ~/.vim/plugin/).

To use it, you can invoke vim (or gvim) with a command like:

gvim -c 'silent call TabMultiDiff()' old-foo foo old-bar bar

Thats obviously kind of long, so you probably want to wrap it in a shell script. My script for doing this is vd (which also depends on v). Note that that it imposes some of my personal preferences, so you may only want to use it as a starting point.

Using Them Together

To use git-multidiff and tab-multi-diff.vim together I have the following in my .gitconfig:

  tool = vd -f

Note that the tool option for multidiff is a command line prefix, not a “tool name” as it is for git difftool. That’s why it’s possible to include a flag. The -f flag shown here is to prevent backgrounding. (It's always seemed weird to me that git difftool has this extra layer of indirection.)

posted Friday, February 10, 2012