2

Let's say I have a file like this

(abc)
(123)
(456)

I want to yank abc and paste it in place of 123 and 456. I would yi) on the first line. Then go down a line and paste it with vi)p. But for the 456, vim will paste the last visual selected text which is 123 instead of abc. The file is now looks like this:

(abc)
(abc)
(123)

This can be solve by specify a register before the yank/paste operation but I usually forget to include it. Is there anyway I can prevent vim visual select from yanking selected text?

2 Answers 2

2

The result of the second paste is determined by the first paste that substitute de default register with what has been overridden.

The standard solution for that is to include the following mapping in your .vimrc file:

xnoremap p pgvy

When you paste in visual mode (x):

  • It select what has been previously selected (gv) and
  • Yank it (y)
1
4

Since patch 8.2.4242 you can use P in place of p in visual mode to put without yanking- i.e., use vi)P in your example to get the desired behavior.


To go slightly further, I have created a plugin visput which enables this behavior for both p and P and also enables . repeat to work after visual operations.

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.