How can I view multiple git diffs side by side in vim

I’d like to be able to run a command that opens up a git diff in vim, with a tab for each file in the diff set.

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.

  • Difference between file created in github and one pushed to github?
  • How can I get the diff between all the commits that occurred between two dates with Git?
  • Shortcut for specifying modified files as arguments to git diff
  • git: Log for 'master' only goes back to date bug?
  • Diff & Merging between different VCS
  • Is it possible to use the “minimal” algorithm for interactive adding?
  • Anyone got any ideas?

  • Jennkins: Command “git rev-parse --is-inside-work-tree”
  • How could I commit to remote branch one by one automatically
  • Git Segmentation fault: 11
  • Why is there a `remotes/origin/HEAD -> origin/master` entry in my `git branch -l -a` output?
  • Xcode The repository “(null)” could not be reached
  • How to you revert a staged file with changes, preserving the changes to when it was staged?
  • 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)

    1. Open files with changes in new vim tabs:

      vim -p $(git diff –name-only)

    2. For every buffer get the diff to your current HEAD with the vcscommand vim plugin

      :VCSVimDiff

    This gives a nice view of the difference, though not in patch form.

    For anything else I would stick to git diff.

    EDIT

    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 git difftool.

    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 tab-multi-diff.vim to .vim/plugin.

    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.
    enter image description here

    Git Baby is a git and github fan, let's start git clone.