How to Paste over Selected Text without Overwriting the Unnamed Register in Vim
Summary: paste with P
in visual mode.
It’s painful to paste over selected text in Vim, because the unnamed register is overwritten by the selected text. Thus, we can not paste the original yanked text twice.
If you have a file:
|
|
You want to copy hello
, paste it over kitty
, and paste it again. You type these commands in Vim.
|
|
You expect to get:
|
|
However, you will get:
|
|
You should use P
in visual mode, so the unnamed register is not changed. Put the original file content in Vim:
|
|
Type ggyyjVPp
, and you will get:
|
|
You can read the help file by :h v_P
for more information.
Tags: