I'm using Vim as a 3-way merge too with Git and sometimes need to take changes from both local and remote branches. kdiff3 can do this with a couple of key presses, is there a way to do this in Vim?


Not exactly what you asked, but may find this useful: Splice plugin: a Vim plugin for resolving conflicts during three-way merge. It has a nice demo screencast on Vimeo.

If you are going to stick with the default vimdiff you could create a function to retrieve the buffer number for the surronding windows and use them to call :diffget twice:

                            *:diffg* *:diffget*
:[range]diffg[et] [bufspec]
        Modify the current buffer to undo difference with another
        buffer.  If [bufspec] is given, that buffer is used.  If
        [bufspec] refers to the current buffer then nothing happens.
        Otherwise this only works if there is one other buffer in diff


The [bufspec] argument above can be a buffer number, a pattern for a buffer
name or a part of a buffer name.  Examples:

    :diffget        Use the other buffer which is in diff mode
    :diffget 3      Use buffer 3
    :diffget v2     Use the buffer which matches "v2" and is in
                diff mode (e.g., "file.c.v2")

You could them use a mapping to assign a call to this function to the keys you were used in kdiff3.

You can find further information on this vimcast.

  • Calling :diffget twice doesn’t seem to work; the second paste overwrites the first one instead of appending to it. Jun 30 '20 at 0:28

yank and put can work without any plugins or extra functions, though it is, perhaps, a bit less convenient than do or dp

Just copy the needed bits from the parent buffers and paste them into the correct spot in the merged buffer. This is also useful if you want just part of a diff block, rather than the whole thing.

You may, at times, need to force Vim to update the diff highlighting with :diffupdate.

  • Documentation seems to imply do instead of dg? Jun 30 '20 at 20:07
  • @FranklinYu Oops, fixed. Thanks for the heads up.
    – 8bittree
    Jul 1 '20 at 20:32

To combine changes from both the target and merge branches in a single command:

You can just delete the lines with Git conflict markers. The following two methods will delete all lines that start with:


Method 1: Manually Entering and Executing a Command


Method 2: Implementing a User Defined Command

"Delete all Git conflict markers
"Creates the command :GremoveConflictMarkers
function! RemoveConflictMarkers() range
  echom a:firstline.'-'.a:lastline
  execute a:firstline.','.a:lastline . ' g/^<\{7}\|^|\{7}\|^=\{7}\|^>\{7}/d'
"-range=% default is whole file
command! -range=% GremoveConflictMarkers <line1>,<line2>call RemoveConflictMarkers()

Vim diffget and diffput will only choose one branch or the other. So the only real solution other than the one given above is to manually yank and paste from both files into the working copy.

  • Give a reason if you are going to downvote. May 15 '18 at 23:53
  • 1
    This is all I do - just delete the markers. May 30 '18 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.