sponsor Vim development Vim logo Vim Book Ad

ConflictMotions : Motions to and inside SCM conflict markers.

 script karma  Rating 18/6, Downloaded by 406    Comments, bugs, improvements  Vim wiki

created by
Ingo Karkat
 
script type
utility
 
description
DESCRIPTION
This plugin defines movement commands and text objects to go to and operate on
conflicting lines, as indicated by many revision control systems, like
Subversion, Git, etc. The source code management system inserts conflict
markers such as <<<<<<<, =======, and >>>>>>> on merges to indicate that the
automatic resolution failed; this plugin helps you with locating and resolving
these conflicts.

RELATED WORKS
To be alerted to the existence of conflict markers and to visually
differentiate the conflicted lines, you can use the highlighting, warnings and
custom buffer status provided by the companion ConflictDetection.vim plugin
(vimscript #4129).

USAGE
]x                      Go to [count] next start of a conflict.
]X                      Go to [count] next end of a conflict.
[x                      Go to [count] previous start of a conflict.
[X                      Go to [count] previous end of a conflict.

]=                      Go to [count] next conflict marker.
[=                      Go to [count] previous conflict marker.
                        Mnemonic: = is in the separator between our and their
                        changes.

ax                      "a conflict" text object, select [count] conflicts,
                        including the conflict markers.

a=                      "a conflict section" text object, select [count]
                        sections (i.e. either ours, theirs, or base) including
                        the conflict marker above, and in the case of "theirs"
                        changes, also the ending conflict marker below.

i=                      "inner conflict section" text object, select current
                        section (i.e. either ours, theirs, or base) without
                        the surrounding conflict markers.

:ConflictTake           From the conflict the cursor is in, remove the markers
                        and keep the section the cursor is inside.
:ConflictTake [none this ours base theirs both all query] [...]
:ConflictTake [-.<|>+*?][...]
                        From the conflict the cursor is in, remove the markers
                        and keep the passed section(s) (in the order they are
                        specified).
                            none, - = delete the entire conflict
                            both    = ours theirs               (+ = <>)
                            all     = ours [base] theirs        (* = <|>)
                            query   = ask which sections to take
                        Note: | must be escaped as \|.
:[range]ConflictTake [none this ours base theirs both all range query] [...]
:[range]ConflictTake [-.<|>+*:?][...]
                        When the cursor is inside a conflict, and the [range]
                        covers part of that conflict:
                        From the conflict the cursor is in, remove the markers
                        and keep the passed range (without contained markers)
                        (and any passed sections in addition; include the
                        "range" / ":" argument to put the range somewhere
                        other than the end).
                        Otherwise, when a large range (like %) is passed:
                        For each conflict that starts in [range], remove the
                        markers and keep the passed section(s) / ask which
                        section(s) should be kept. You can answer the question
                        with either the symbol or the choice's starting
                        letter. An uppercase letter will apply the choice to
                        all following conflicts.

<Leader>xd              Delete the entire current conflict / all conflicts in
                        the selection.
<Leader>x<              Keep our changes, delete the rest.
<Leader>x|              Keep the change base, delete the rest.
<Leader>x>              Keep their changes, delete the rest.

<Leader>x.              Keep the current conflict section, delete the rest.
{Visual}<Leader>x.      From the conflict the cursor is in, remove the markers
                        and keep the selected lines (without contained markers).
                        For each conflict that starts in the selection, remove
                        the markers and ask which section(s) should be kept.
 
install details
INSTALLATION
This script is packaged as a vimball. If you have the "gunzip" decompressor
in your PATH, simply edit the *.vmb.gz package in Vim; otherwise, decompress
the archive first, e.g. using WinZip. Inside Vim, install by sourcing the
vimball or via the :UseVimball command.
    vim ConflictMotions*.vmb.gz
    :so %
To uninstall, use the :RmVimball command.

DEPENDENCIES
- Requires Vim 7.0 or higher.
- Requires the CountJump plugin (vimscript #3130).
- Requires the ingo-library.vim plugin (vimscript #4433), version 1.019 or
  higher.
- repeat.vim (vimscript #2136) plugin (optional)
- visualrepeat.vim (vimscript #3848) plugin (optional)

CONFIGURATION
For a permanent configuration, put the following commands into your vimrc:

To change the default motion mappings, use:
    let g:ConflictMotions_ConflictBeginMapping = 'x'
    let g:ConflictMotions_ConflictEndMapping = 'X'
    let g:ConflictMotions_MarkerMapping = '='
To also change the [ / ] prefix to something else, follow the instructions for
CountJump-remap-motions. (This requires CountJump 1.60.)

To change the default text object mappings, use:
    let g:ConflictMotions_ConflictMapping = 'x'
    let g:ConflictMotions_SectionMapping = '='
To also change the i / a prefix to something else, follow the instructions for
CountJump-remap-text-objects. (This requires CountJump 1.60.)

If you don't want the mappings for :ConflictTake:
    let g:ConflictMotions_TakeMappingPrefix = ''
To redefine the mappings, either clear the prefix and use the
<Plug>(ConflictMotionsTake...) mapping targets, or adapt via the prefix and
mapping configuration, e.g.:
    let g:ConflictMotions_TakeMappingPrefix = '<Leader>='
    let g:ConflictMotions_TakeMappings = [['d', 'None'], ['x', 'This'], ['o', 'Ours'], ['b', 'Base'], ['t', 'Theirs']]
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
ConflictMotions-2.10.vmb.gz 2.10 2014-07-21 7.0 Ingo Karkat - ENH: Define both normal and visual mode mappings for all mappings, not the exclusive either-or. The new visual mode mappings will select the corresponding section in all conflicts found in the selected range. (Application on a partially selected conflict is denied by an error since version 2.02.)
- ENH: Enable repeat of all mappings, also (with visualrepeat.vim) across modes. Thanks to Maxim Gonchar for the suggestion.
- Handle folded ranges overlapping the conflicts. Thanks to Maxim Gonchar for reporting this. When querying which conflict sections to keep, open folds so that if possible the entire conflict is visible, but at least the section markers.
- Re-allow combining range inside conflict with section argument, but only for the :ConflictTake command, not the mappings.
ConflictMotions-2.02.vmb.gz 2.02 2014-07-19 7.0 Ingo Karkat - Regression: Version 2.01 introduced a bad offset calculation, potentially resulting in left-over conflicts, e.g. on :%ConflictTake.
- Do not allow combination of a range inside a conflict with a section argument, as the two contradict each other. Print an error instead.
ConflictMotions-2.01.vmb.gz 2.01 2014-05-31 7.0 Ingo Karkat - BUG: "E16: Invalid range" error when taking a conflict section of a hunk at the end of the file. Use ingo#lines#PutBefore(). Thanks to Kballard for reporting this on the Vim Tips Wiki and suggesting the fix.
- BUG: Taking conflicts where a single hunk spans the entire buffer adds a blank line. Use ingo#lines#Replace(), which now handles this. Thanks to Kballard for reporting this on the Vim Tips Wiki.
- The CountJump operator-pending mapping will beep when the inner conflict section is empty, but for taking such a section, the beep is unexpected. Detect this special case and skip the CountJump text object then. Thanks to Kballard for reporting this on the Vim Tips Wiki.
- Abort on error of :ConflictTake.
- Use ingo#register#KeepRegisterExecuteOrFunc(). *** You need to update to ingo-library (vimscript #4433) version 1.019! ***
ConflictMotions-2.00.vmb.gz 2.00 2013-04-23 7.0 Ingo Karkat - FIX: Don't create the default mapping for <Plug>(ConflictMotionsTakeSelection) in select mode; it should insert a literal <Leader> there.
- Add the :ConflictTake command to resolve a conflict by picking a section(s).
- Add dependency to ingo-library (vimscript #4433).
ConflictMotions-1.10.vmb.gz 1.10 2012-09-06 7.0 Ingo Karkat The [z / ]z mappings disable the built-in mappings for moving over the current open fold. Oops! Change default to [= / ]= / i= / a=. (= as for the characters in the separator between our and their change).
ConflictMotions.vba.gz 1.00 2012-03-28 7.0 Ingo Karkat Initial upload
ip used for rating: 54.196.159.11

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
SourceForge.net Logo