I'm using vimdiff as tool when comparing with git difftool.
I want to compare 2 commits with git difftool <commit1> <commit2>.
Today, I have to exit every vimdiff view with :qa to get to the next file pair.
Sometimes, the list of file pairs can be huge with this type of comparison. Then, I have to type :qa dozens of times (or :cq when done).
Is there a way to display all compared file pairs (with at least 1 change) in a QuickFix, Location List or something similar?
Then, it would be must easier to get an overview and to scroll through all changes and show only the diff of selected files.
Extract of my .gitconfig:
[diff]
tool = vimdiff
[difftool]
prompt = false
# Be able to abort all diffs with `:cq` or `:cquit`
trustExitCode = true
vimdiff --version:
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Apr 18 2022 19:26:30)
Included patches: 1-3995
git --version:
git version 2.34.1
2 Answers 2
The vimdiff in tool = vimdiff is not actually vimdiff. It's a script that doesn't really allow for what you want.
Sadly, the -d flag, as in $ git difftool -d, is not helpful as is. It opens two Netrw windows where you can effectively see which files have changes but the whole user experience is a lot more clunky than repeating :qa<CR>, even a hundred times:
IMO, it's a pain in the ass compared to the UX provided in GUI difftools:
But, since you mentioned the quickfix, you might like git-jump, which lets you do:
$ git jump diff
Which is pretty good for navigating from one change to another but doesn't really help solving the problem of seeing the actual diff.
Maybe a third-party plugin like this one could help but you would have to come up with a proper Git integration.
That sounds like a cool week-end project.
Comments
git difftool -d
you can
- j k moving to selected dir, presse enter to open dir
- move cursor to you want to open file
- pressed t to open file in new tab
- press gt or gT to go back dir buffer(netrw
- ctrl+w ctrl+w shift left buffer and rifht buffer
- do again 1 2 3
- now you have open 3 tab,but only 2 buffer(file) opend
- gt or gT to any tab that has display a file buffer
- :vsp to split vertical window
- :bn or :bp
- :windo diffthis
i code a vim scrip to expand netrw tree at all ,so i can search it , also can open diff easy...
git diffdoes for you. What are you looking for thatgit diff --stat <commit1> <commit2>(lists all modified files) andgit diff <commit1> <commit2>(lists all changes) don't already provide?git difffor some time. But tbh, I'm looking for a better looking diff, e.g. with a side-by-side view. I recently checked outvimdiffand I got a good-looking overview out of the box. I can stick withgit diff, but wondered, if could usevimdiff. Then I ran into the multiple file pairs "problem" as stated in this SO question.git jumptool in romainl's answer is a vaguely similar idea, and you might be able to steal some items from it.nvim >= 0.7.0. There, you get a nice looking tree view with:DiffviewOpen <commit1> <commit2>. Since this is not what I asked for originally (git difftool), I will not post this as accepted answer.