Using Vim as a merge program for Mercurial

Vim's diff mode (aka "vimdiff") allows vim to be used to do hg merges.

Configuration is quite simple. In your ~/.hgrc file, add the following:

[ui]
merge = vimdiff

[merge-tools]
vimdiff.executable = vim
vimdiff.args = -d $local $other

Note: these are very simple settings. See 'man hgrc' for a full explanation of configuring hgrc files

If you are unfamiliar with vim's diff mode, you may find ":help diff" useful to read (see in particular the ":diffget" and ":diffput" commands). Also, diff mode by default uses folds, so "help folding" may be useful.

The above "args" command only shows the conflicting versions in the merge. If you would like to also see the base version of the file (i.e. their common ancestor), you can call " -d $local $other $base". This will show all three files. Note that when more than two files are diffed, the keyboard shortcuts for :diffget ("do") and :diffput ("dp") will not work unless you remap them to include a buffer spec.

There has been some confusion on da internets about using Vim's DifDiff extension to do hg merges. DirDiff can be used for fancy "hg diff" browsing, but will not work with "hg merge".