tags:

views:

301

answers:

2

I'd like to be able to run a command that opens up a git diff in vim, with a tab for each file in the diff set.

So if for example I've changed files foo.txt and bar.txt in my working tree and I ran the command I would see vim open with two tabs. The first tab would contain a side-by-side diff between foo.txt in my working tree and foo.txt in the repository, and the second tab would contain a side-by-side diff for bar.txt.

Anyone got any ideas?

+2  A: 

The way I would do this (though it isn't a single command)

  1. Open files with changes in new vim tabs:

    vim -p $(git diff --name-only)

  2. For every buffer get the diff to your current HEAD with the vcscommand vim plugin

    :VCSVimDiff

This gives a nice view of the difference, though not in patch form.

For anything else I would stick to git diff.

EDIT

Like Dave writes below, steps 1 and 2 can be combined by using

vim -p $(git diff --name-only) -c "tabdo VCSVimDiff"
honk
You could possibly combine it into one command, which could be put into a shell script or function. (untested code ahead):vim -p $(git diff --name-only) -c "tabdo VCSVimDiff"
Dave Kirby
I tried both the one-liner and the 2 part commands. It only does the diff for the last tab opened. Other tabs have to have :VCSVimDiff called on them. Solutions?.. I'd love to get all of the tabs running diffs.
Scoobie
A: 

Although it doesn't do exactly what you want, git difftool is probably your best bet. The out of the box behavior of 'git difftool --tool=vimdiff --no-prompt HEAD' is to launch vimdiff sequentially for each file in the working dir with changes.

William Pursell