What's the recommended way of copying changes with vimdiff?

When comparing files, and updating a source code repository, I like to use vimdiff. To copy changes made from one file to the other, I usually use a key sequence like this:-

Shift + V (select line)
k or j; { or }; Up or down arrow keys (select more lines)
y  (copy selected lines)
Ctrl + w, left/right arrow (move to other pane)
p (paste lines)

Vim, being the master of keyboard shortcuts, should surely have an easier way of performing this same task. Is there one? What do you use to manually update source-code changes?

Asked By: Alex Leach

||

do (diff obtain) and dp (diff put) is what you need. Here is a
small list of other helpful normal mode commands in this context.

]c               - advance to the next block with differences
[c               - reverse search for the previous block with differences
do (diff obtain) - bring changes from the other file to the current file
dp (diff put)    - send changes from the current file to the other file
zo               - unfold/unhide text
zc               - refold/rehide text
zr               - unfold both files completely
zm               - fold both files completely

NOTE:
Both do and dp work if you are on a block or just one line under a block in normal mode but not in visual mode.
When selecting lines of text in visual mode, you must use the normal commands

  • :'<,'>diffget and
  • :'<,'>diffput.

See also :h copy-diffs.

:diffupdate will re-scan the files for changes.

Answered By: Marco
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.