Differences between revisions 1 and 5 (spanning 4 versions)
Revision 1 as of 2009-09-18 23:59:05
Size: 1399
Editor: jduell
Comment:
Revision 5 as of 2010-10-27 12:09:39
Size: 2458
Editor: PaulBoddie
Comment: Worked on the formatting, wording. (Trying to understand how to use vimdiff myself!)
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
== Using Vim as a merge program for Mercurial == = Using Vim as a Merge Program for Mercurial =
Line 3: Line 3:
Vim's [[http://www.vim.org/htmldoc/diff.html|diff mode]] (aka "vimdiff") allows vim to be used to do hg merges. Vim's [[http://www.vim.org/htmldoc/diff.html|diff mode]] (aka `vimdiff`) allows Vim to be used to do a `hg merge`.
Line 5: Line 5:
Configuration is quite simple. In your ''~/.hgrc'' file, add the following: Here's my favorite way to use Vim to do Mercurial merges.

To configure, add the following to your `~/.hgrc` file:
Line 12: Line 15:
vimdiff.args = -d $local $other vimdiff.args = -d $base $local $output $other +close +close
Line 14: Line 17:
'''Note: these are very simple settings. See 'man hgrc' for a full explanation of configuring hgrc files'''
Line 16: Line 18:
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 `args` command opens all 4 versions of `file`, defined as follows:
Line 18: Line 20:
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.  * `file~base` - the common ancestor
 * `file.orig` - the local tree's version
 * `file` - the merge result (you resolve your conflicts into this file: it's the one that `hg` considers the 'fixed' version when you're done)
 * `file~other` - the version from the other tree that you're merging from
Line 20: Line 25:
There has been some confusion on da internets about using Vim's [[http://www.vim.org/scripts/script.php?script_id=102|DifDiff]] extension to do hg merges. Dir``Diff can be used for [[http://mercurial.selenic.com/wiki/ExtdiffExtension|fancy "hg diff" browsing]], but will not work with "hg merge". Since you are typically most interested in the `file` and `file~other` buffers (and since Vim's keyboard shortcuts for `:diffget` (`do`) and `:diffput` (`dp`) only work when two buffers are open), we close the windows for the other two buffers. They're still around, though: if the merge is complex and you want to see them, use `:bnext` and `:bprev`.

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.

== If things go terribly wrong ==

Quit Vim via `:cq`. It won't save, and it will return an error code, so Mercurial will not consider the file merged yet, and you can try again via `hg resolve filename` (`hg resolve -l` to see list of files, in case you get '''really''' confused).

If you decide you hate using `vimdiff`, for instance, you can issue a `:cq`, set...

{{{
ui.merge = internal:merge
}}}

...in your `.hgrc`, and run `hg resolve`, and you'll be back to merging via `<<<<<<<` and `>>>>>>>` marks in the file. So you can try `vimdiff` out as a merge tool without getting into a world of pain if you don't like/understand it.

== DirDiff and merging ==

There has been some confusion about using Vim's [[http://www.vim.org/scripts/script.php?script_id=102|DirDiff]] extension to do a `hg merge`. !DirDiff can be used for [[http://mercurial.selenic.com/wiki/ExtdiffExtension|fancy "hg diff" browsing]] (a great way to look at patches), but will not work with `hg merge`.

(!) See `man hgrc` for a full explanation of configuring `hgrc` files.

Using Vim as a Merge Program for Mercurial

Vim's diff mode (aka vimdiff) allows Vim to be used to do a hg merge.

Here's my favorite way to use Vim to do Mercurial merges.

To configure, add the following to your ~/.hgrc file:

[ui]
merge = vimdiff

[merge-tools]
vimdiff.executable = vim
vimdiff.args = -d $base $local $output $other +close +close

The args command opens all 4 versions of file, defined as follows:

  • file~base - the common ancestor

  • file.orig - the local tree's version

  • file - the merge result (you resolve your conflicts into this file: it's the one that hg considers the 'fixed' version when you're done)

  • file~other - the version from the other tree that you're merging from

Since you are typically most interested in the file and file~other buffers (and since Vim's keyboard shortcuts for :diffget (do) and :diffput (dp) only work when two buffers are open), we close the windows for the other two buffers. They're still around, though: if the merge is complex and you want to see them, use :bnext and :bprev.

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.

If things go terribly wrong

Quit Vim via :cq. It won't save, and it will return an error code, so Mercurial will not consider the file merged yet, and you can try again via hg resolve filename (hg resolve -l to see list of files, in case you get really confused).

If you decide you hate using vimdiff, for instance, you can issue a :cq, set...

ui.merge = internal:merge

...in your .hgrc, and run hg resolve, and you'll be back to merging via <<<<<<< and >>>>>>> marks in the file. So you can try vimdiff out as a merge tool without getting into a world of pain if you don't like/understand it.

DirDiff and merging

There has been some confusion about using Vim's DirDiff extension to do a hg merge. DirDiff can be used for fancy "hg diff" browsing (a great way to look at patches), but will not work with hg merge.

(!) See man hgrc for a full explanation of configuring hgrc files.

MergingWithVim (last edited 2016-07-24 18:47:02 by ThomasDeSchampheleire)