3

Is it possible to use vim diff to open and compare all the differences between HEAD and the files in the working directory?

4

To view unstaged modifications to your git working tree in vimdiff, try:

git difftool --tool=vimdiff

or for staged changes

git difftool --tool=vimdiff [ --staged | --cached ]

These commands are invoking git difftool and specifying vimdiff at invocation, so should work without any prior configuration.
However, until you configure vimdiff as the default difftool, you will have to continue passing the --tool=vimdiff option to git difftool.
Also, I suggest incrementally increasing your usage of vim as a git diffing tool, some people suggest jumping right in re-mapping the git diff command to use vimdiff, but retaining the ability to use git diff can still be useful.
Also some people suggest turning off prompting, i.e. running

git config --global difftool.prompt false

I don't use this because I want to go back to a shell between viewing files, so I can cancel out of the diff'ing if necessary.

making edits right there in vimdiff

An advantage of using vim over git diff is that when you are viewing unstaged or staged files in vimdiff you can go ahead and change the file right there in vim, which is really handy.
You need to use :w! to force past vims warning of modifying a read only file though. Also, if you change a file that was staged, you will need to re-stage to include the edit into the next commit.

Setting vimdiff as your git difftool

You can use

git config --global diff.tool vimdiff

or put

[diff]
    tool = vimdiff

into your ~/.gitconfig or to be repo specific: .git/config

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.