0

In Vim, if I have a file like this:

one
two

I visually select "one" by using ve and then yank it by using y, it gets copied to the default register (referred to as the "clipboard").

If I then visually select "two" by using ve and paste the contents of the default register on top of it using p, the file is updated to look like this:

one
one

The value of "two" has been yanked to the default register, and if I want to paste the value of "one" again in another location, I would have to yank it again.

Is there a way to paste the contents of the default register on top of a visual selection in Vim without overwriting its value in the default register?

I understand that there are alternative approaches, such as using search and replace, but I'm specifically asking about the visual selection features in Vim.

1
  • This behavior is quite logical. Your old item one moves from unnamed register to register number zero once you paste it onto selected text. The deleted/selected text is now in the unnamed register. You can check this by the command :reg. And you can paste your old item one by simply typing "0p Jul 1, 2023 at 15:21

1 Answer 1

0

Is there a way to paste the contents of the default register on top of a visual selection in Vim without overwriting its value in the default register?

Yes, paste it with P instead of p. You can see :help v_P for details.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .