Vim Tips Wiki
Advertisement

The visual mode put command (:help v_p) can be used to paste previously copied text onto a visual selection, i.e. to replace selected test with previously yanked text.

I find the default behavior of this command quite incongruous because this paste command has a side effect: It also copies the text that is being replaced.

The internal reason for this behavior can be easily spotted on the help (:help v_p) for the visual paste command:

... Implementation detail: it actually works by first putting the register after the selection and then deleting the selection.

So, it is not different than just pressing 'dP' after visual selecting the text to replace.

A quick solution to change the default behaviour of the visual mode command is to just remap with:

vnoremap p "_dP

Here we simply discard the deleted text by storing it into the black hole register.

Advertisement