Vimdiff and git all at once

diff()gitvimvimdiff

I use vimdiff as my difftool with git.

Let's say that I've changed twelve files. The problem is that sometimes I run git diff and around the fourth or fifth file I see something that I want to edit/change. Sometimes I need to make a few more changes outside of this. The problem is that I can't just :qa and go back to hacking, because there are six or seven more diffs that pop up in vimdiff. It gets really tedious to :qa all of these files without looking every time that I want to abort a git diff.

Is there any way to set up vimdiff as git's difftool such that all of the diffs open in the same vim instance, e.g. in separate tabs?

Best Answer

You could use the vim plugins published here. Then you just need to set the difftool:

[multidiff]
  tool = vd -f

As an alternative application I would suggest meld, which will show you modified files - you can then select just the files who's diffs you want to see.

See the screenshot here for an example.

Further to Marcos useful comment, as a third (manual alternative) if you want to use vimdiff I would recommend following meld's strategy in a script (possibly python):

  • use git diff-files --name-status and git diff-index --name-status --cached HEAD to identify files that need to be examined.
  • Get cached versions of these files and place in /tmp/
  • Open all of these files - the changed files and their cached versions - at once in vimdiff - though most likely not possible in the sense that you require- see below.

However, as vimdiff itself doesn't seem to handle multiple diff tabs natively I recommend one of my other suggestions above.

Related Question