To stop pasting over a selection from yanking that selection, I would like to remap p so that it doesn't yank the just-rewritten selection:

vim.keymap.set("x", "p", [["_dP]])
xnoremap p "_dP

The remap deletes the text into a throwaway register first and then pastes. Unfortunately, as you can see, if a register were specified before pressing p, then it won't be used by the remap.

E.g. one of my main workflows is to select many lines and replace them with the system clipboard with "+p. The above mapping totally messes that up.

How can I remap for p only, and not for "+p, "ap, "0p etc.?

1 Answer 1


I believe the following mapping should do the job on recent version of Vim:

xnoremap p P

The Vim 9 documentations says (:h put-Visual-mode):

With |P| the unnamed register is not changed (and neither the selection or
clipboard), you can repeat the same change. But the deleted text cannot be
used.  If you do need it you can use |p| with another register.  E.g., yank
the text to copy, Visually select the text to replace and use "0p .  You can
repeat this as many times as you like, and the unnamed register will be
changed each time.

But otherwise I would do:

xnoremap "+p "+p
xnoremap "ap "ap
xnoremap "0p "0p
xnoremap p "_dP
  • 1
    is there a way to specify "any register" automatically? Instead of generating the mappings for all registers manually. Mar 25 at 5:34
  • Not that I'm aware off :-/ Mar 25 at 5:51
  • 1
    I think for "any register" you would have to implement a function and use v:register
    – D. Ben Knoble
    Mar 27 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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