How can I view multiple git diffs side by side in vim
So if for example I’ve changed files foo.txt and bar.txt in my working tree and I ran the command I would see vim open with two tabs. The first tab would contain a side-by-side diff between foo.txt in my working tree and foo.txt in the repository, and the second tab would contain a side-by-side diff for bar.txt.
Anyone got any ideas?
4 Solutions collect form web for “How can I view multiple git diffs side by side in vim”
The way I would do this (though it isn’t a single command)
Open files with changes in new
vim -p $(git diff –name-only)
For every buffer get the diff to your current HEAD with the vcscommand vim plugin
This gives a nice view of the difference, though not in patch form.
For anything else I would stick to
Like Dave writes below, steps 1 and 2 can be combined by using
vim -p $(git diff --name-only) -c "tabdo VCSVimDiff"
Adapted Benjamin Bannier + Dave Kirby’s answer above for fugitive users.
Because I use fugitive.vim, I adapted the above for my most frequent use case, looking at the diff between the last 2 commits:
vim -p $(git diff --name-only HEAD~1 HEAD) -c "tabdo :Gdiff HEAD~1"
Loading all the changes into tabs is so much better than going through them sequentially with
Although it doesn’t do exactly what you want, git difftool is probably your best bet. The out of the box behavior of ‘git difftool –tool=vimdiff –no-prompt HEAD’ is to launch vimdiff sequentially for each file in the working dir with changes.
This simple plugin has worked for me: TabMultiDiff. It basically creates a diff tab for each pair of files passed to vim. The tab is named after the second file in each pair.
Note it is not plugin manager compatible, so you need to manually install it by copying
Here is a screenshot of comparing two pairs of simple files (aaa/aab and aac/aad). Note that I also use vim-scripts/diffchar.vim which is why individual characters are highlighted.