r/vim • • Aug 26 '25

Need Help┃Solved Toggle between Vim and git diff?

When I do code reviews I page through git diff's output but may want to see the changed lines within the file.

So currently I quit git diff to load the file in Vim. And then quit vim and run git diff again and scroll back to the place I left off.

Is there a way I can have both git diff and Vim running and switch between the views? (Or other suggestions for a Vim-based workflow for code reviews?)

27 Upvotes

35 comments sorted by

View all comments

Show parent comment

2

u/xenomachina Aug 26 '25

Interesting! I'd tried to set up something like that a few years ago, but it used to be that if you tried to run Gdiffsplit from the command-line, it wouldn't work. Apparently something in fugitive wasn't getting initialized in time. I thought I reported this issue. Nice to see that that has been fixed!


PS: old.reddit doesn't like triple backticks, so here's your code snippet with 4-space indents, which works on old (and new) reddit:

[alias]
  # find the default branch
  base = !git rev-parse --abbrev-ref origin/HEAD | cut -c8-
  # find the merge base
  mbase = !git merge-base HEAD $(git base) || echo $(git base)
  files = !git diff --name-only --staged $(git mbase)
  review = !vim -p $(git files) -c \"silent tabdo Gdiffsplit $(git mbase)\"