There was an interesting post regarding painless merge conflict resolution in git that popped up on programming reddit today, and it got me thinking- there has to be a way to get true three-way merge working in vim.

It turns out there is, you just have to do some finagling to do so. By default, the git mergetool logic for vim and gvim is only a two-way merge: you can see the local, merged, and remote versions, but the base version is nowhere to be found. The following commands make vim use a command line of your choosing and give you a four-pane view of your merge.

$ git config --global mergetool.gvimdiff3.cmd 'gvim -f -d -c "wincmd J" "$MERGED" "$LOCAL" "$BASE" "$REMOTE"'
$ git config --global mergetool.vimdiff3.cmd 'vim -f -d -c "wincmd J" "$MERGED" "$LOCAL" "$BASE" "$REMOTE"'
Vim Three-Way Merge

Then pick your poison by running one of the following, depending on whether you want the terminal or the GUI:

git config --global merge.tool vimdiff3
git config --global merge.tool gvimdiff3

The end result is three panes along the top (local, base, and remote respectively), and the merge work-in-progress is on the bottom. In addition, all four panes are still locked together for scrolling.

I'd like to submit this to upstream, perhaps as a pseudo-command like above or simply replacing the existing vimdiff and gvimdiff commands. We'll have to see which one is more well received.