Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Viewing all `git diffs` with vimdiff

People also ask

How do I check my git diff tool?

Type git config diff. tool winmerge . Verify it worked by typing git difftool . Get rid of the prompt typing git config --global difftool.

How do I navigate in Vimdiff?

Ctrl+w and right and left arrow can be used to move between any split windows on vim, not only vimdiff splits. These keys do work here on cygwin; also, Ctrl+w w also moves to the next window, but without the delay you mentioned.


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

Typing git difftool yields the expected behavior.

Navigation commands,

  • :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.

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.


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

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>

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