Search code examples
vimvimdiffvim-fugitive

The hotkey "dp"(diff put) has a mapping conflict with vim-fugitive, when copying changes with vimdiff


When comparing files, I like to use vimdiff(or vim -d) and I know a recommended way of copying changes with vimdiff is:

]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

and I also know that

  • :diffget is the same as do

  • :diffput is the same as dp

All these commands work perfectly (including:diffput), but when I input dp, nothing changes and an error sound is produced.

I think this is because of a hotkey mapping conflict with vim-fugitive, which has a hotkey dp:

dp    :Git! diff (p for patch; use :Gw to apply)
dp    :Git add --intent-to-add (untracked files)

How to fix this problem? Thank you.


Solution

  • You can still invoke the built-in mapping via :normal! dp.

    If you need this multiple times, better undefine the original buffer-local mapping:

    :nunmap <buffer> dp
    

    However, as @Kent has commented, fugitive's dp mapping is only active in a preview window (cp. :h fugitive-:Gstatus). Since you should use normal windows for diffing and merging, there shouldn't be an overlap.