Viewing all `git diffs` with vimdiff

GitVimDiffVimdiff

Git Problem Overview


I setup git diff to wrap into vimdiff, using "Git Diff with Vimdiff" as a guide, and it's working as expected unless there are many files with changes.

When there are multiple files with changes and I run git diff, it opens the first file and, after quitting the first instance of vimdiff, I'm presented with the following message:

external diff died, stopping at filename

This is a completely different behavior than I am used to. I had a similar setup in the past with SVN and, when diffing against multiple files, I would review the first file, then write and quit using :wq and the next file with differences would open up.

This is not the case with Git. I tried :n[ext], but doing so does not fill the left window with the original file so that it can be diffed against the modified version.

Git Solutions


Solution 1 - Git

git config --global diff.tool vimdiff
git config --global difftool.prompt false

Typing git difftool yields the expected behavior.

  • :qa in vim cycles to the next file in the changeset without saving anything.
Aliasing (example)
git config --global alias.d difftool

.. will let you type git d to invoke vimdiff.

Advanced use-cases,
  • By default, git calls vimdiff with the -R option. You can override it with git config --global difftool.vimdiff.cmd 'vimdiff "$LOCAL" "$REMOTE"'. That will open vimdiff in writeable mode which allows edits while diffing.
  • :wq in vim cycles to the next file in the changeset with changes saved.

Solution 2 - Git

You can try git difftool, it is designed to do this stuff.

First, you need to config diff tool to vimdiff

git config diff.tool vimdiff

Then, when you want to diff, just use git difftool instead of git diff. It will work as you expect.

Solution 3 - Git

Git accepts kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge,
and opendiff as valid diff tools. You can also set up a custom tool. 

git config --global diff.tool vimdiff
git config --global diff.tool kdiff3
git config --global diff.tool meld
git config --global diff.tool xxdiff
git config --global diff.tool emerge
git config --global diff.tool gvimdiff
git config --global diff.tool ecmerge

Solution 4 - Git

For people who want to use another diff tool not listed in git, say with nvim. here is what I ended up using:

git config --global alias.d difftool -x <tool name>

In my case, I set <tool name> to nvim -d and invoke the diff command with

git d <file>

Solution 5 - Git

If you want to permanently use vimdiff for git diff, you can set the ~/.gitconfig file:

git config --global diff.tool vimdiff

and then you can use git difftool to diff.

If you only want to temporarily use vimdiff, you can run the command every time:

git difftool --tool=vimdiff

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionchuckgView Question on Stackoverflow
Solution 1 - GitchuckgView Answer on Stackoverflow
Solution 2 - GitczchenView Answer on Stackoverflow
Solution 3 - GitNanhe KumarView Answer on Stackoverflow
Solution 4 - Gitsalty-cat-fishView Answer on Stackoverflow
Solution 5 - GitVictorView Answer on Stackoverflow