Size: 2331
Comment: fixing typos
|
Size: 4053
Comment: Attempted to add some concrete instructions.
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
== Using Vim as a merge program for Mercurial == Vim's [[http://www.vim.org/htmldoc/diff.html|diff mode]] (aka "vimdiff") allows vim to be used to do hg merges. |
= Using Vim as a Merge Program for Mercurial = |
Line 4: | Line 3: |
Here's my favorite way to use vim to do mercurial 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 6: | Line 5: |
Configuration: In your ''~/.hgrc'' file, add the following: | Here's one way to use Vim to do Mercurial merges. To configure, add the following to your `~/.hgrc` file: |
Line 16: | Line 17: |
The 'args' command opens all 4 version of 'file': 'file~base' = common ancestor, 'file.orig' = local tree's version, 'file' = merge result (i.e. resolve your conflicts into this file: it's the one that hg considers the 'fixed' version when you're done), and 'file~other' = 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/:bprev. | |
Line 18: | 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. | When presenting a merge, Vim will show two windows side by side (unless the configuration has been changed to show them stacked vertically). You may even get Vim's exuberant colour choices: |
Line 20: | Line 20: |
'''If things go terribly wrong:''' quit vim via ":cq". It won't save, and 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 ":cq", set 'ui.merge = internal:merge" in your .hgrc, and run 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. | || '''The merge result''' || '''The "other" version''' || || ''This window will be the one you work in to get the desired merge'' || ''This window provides desirable content from the other version'' || ||<style="background-color: #0dd; color: #00d; font-family: monospace"> ||<style="background-color: #d00; color: #fff; font-family: monospace">content provided by this version || ''additions to consider'' || ||<style="background-color: #d00; color: #fff; font-family: monospace">content provided by this version ||<style="background-color: #0dd; color: #00d; font-family: monospace"> || ''deletions to consider'' || ||<style="background-color: #d0d; color: #fff; font-family: monospace">changed content ||<style="background-color: #d0d; color: #fff; font-family: monospace"> modified content || ''character-level changes to consider'' || |
Line 22: | Line 26: |
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. 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". | In preparing the merge result, the objective is to "get" or "obtain" diffs from the other version. This can be done by navigating to regions in a window and then... |
Line 24: | Line 28: |
''See 'man hgrc' for a full explanation of configuring hgrc files'' | * In the merge result window, using the `do` (`diffget`) command to get the diff from the other version. * In the other version window, using the `dp` (`diffput`) command to put the diff into the merge result. Once the merge operations have been performed, the buffers can be written out. == The technical details == 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 [[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 one 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
When presenting a merge, Vim will show two windows side by side (unless the configuration has been changed to show them stacked vertically). You may even get Vim's exuberant colour choices:
The merge result |
The "other" version |
|
This window will be the one you work in to get the desired merge |
This window provides desirable content from the other version |
|
|
content provided by this version |
additions to consider |
content provided by this version |
|
deletions to consider |
changed content |
modified content |
character-level changes to consider |
In preparing the merge result, the objective is to "get" or "obtain" diffs from the other version. This can be done by navigating to regions in a window and then...
In the merge result window, using the do (diffget) command to get the diff from the other version.
In the other version window, using the dp (diffput) command to put the diff into the merge result.
Once the merge operations have been performed, the buffers can be written out.
The technical details
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.