4

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
asked Jun 6, 2022 at 10:30
5
  • If someone knows, I'm interested in the answer to your question, but at the same time, if you want to see all the diffs, that's what a plain git diff does for you. What are you looking for that git diff --stat <commit1> <commit2> (lists all modified files) and git diff <commit1> <commit2> (lists all changes) don't already provide? Commented Jun 6, 2022 at 12:51
  • I lived with git diff for some time. But tbh, I'm looking for a better looking diff, e.g. with a side-by-side view. I recently checked out vimdiff and I got a good-looking overview out of the box. I can stick with git diff, but wondered, if could use vimdiff. Then I ran into the multiple file pairs "problem" as stated in this SO question. Commented Jun 6, 2022 at 13:52
  • That's a fair point, it would be nice to have a better diff. And wow, Googling "git diff viewer" gave me half a million hits, there must be something good among all those results! Anyway, I still use the CLI git diff, but if you do find something good you like, comment back here, I'd be interested. Commented Jun 6, 2022 at 14:39
  • If you're up for it, a pretty big project (much bigger than a single weekend I think) would be to write an improved version of Git's difftool and mergetool commands that makes some assumptions about the back end tools involved, but not so many assumptions that it can't be made to work with common editors and viewers. The git jump tool in romainl's answer is a vaguely similar idea, and you might be able to steal some items from it. Commented Jun 6, 2022 at 16:26
  • 1
    After doing some more research, I will continue with diffview. Requirement: 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. Commented Jun 6, 2022 at 20:49

2 Answers 2

5

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:

vimdiff

IMO, it's a pain in the ass compared to the UX provided in GUI difftools:

filemerge

But, since you mentioned the quickfix, you might like git-jump, which lets you do:

$ git jump diff

git-jump

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.

answered Jun 6, 2022 at 12:51
Sign up to request clarification or add additional context in comments.

Comments

0
git difftool -d

you can

  1. j k moving to selected dir, presse enter to open dir
  2. move cursor to you want to open file
  3. pressed t to open file in new tab
  4. press gt or gT to go back dir buffer(netrw
  5. ctrl+w ctrl+w shift left buffer and rifht buffer
  6. do again 1 2 3
  7. now you have open 3 tab,but only 2 buffer(file) opend
  8. gt or gT to any tab that has display a file buffer
  9. :vsp to split vertical window
  10. :bn or :bp
  11. :windo diffthis

i code a vim scrip to expand netrw tree at all ,so i can search it , also can open diff easy...

Fedor
24.9k46 gold badges61 silver badges190 bronze badges
answered Feb 26, 2023 at 17:48

1 Comment

This comment has many misspellings making it very difficult to understand. Please correct the spelling errors and make sure the steps are clear and easy to follow. Thank you.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.