Vim Tips Wiki
Advertisement

Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).

Please use new tips to discuss whether this page should be a permanent tip, or whether it should be merged to an existing tip.
created June 6, 2009 · complexity basic · version 7.0

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

However, the default behavior of this paste command has a side effect: It also copies the text that is being replaced. As explained in :help v_p:

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

So, it is the same as pressing dP after visually 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.

Comments

I'd suggest either mapping this to <Leader>p or retain this mapping, and map the original behaviour of p to <Leader>p. I.e.,

nnoremap <Leader>p p
nmap p "_p

(Spiiph 00:07, 29 July 2009 (UTC))

Advertisement