9

If I try to copy a word via this yw – yank the current word and paste it to somewhere, it works but If I try to paste it somewhere else one more time old world gets lost with previous replaced word.

I want to paste multiple times with the original yanked word.

1

2 Answers 2

9

You should use the register 0. It contains the last yanked text.

By default, c, d, y use the unnamed register "" to store all modified text.

But the numbered registers "0 contains the previously yanked text and only that. You can use :

"0p

With confidence it will past the last yanked text.

2

As of current vim (since 2022-05-06) you can use P in visual mode to paste over a selection without overriding unnamed register (:h v_P):

With |p| the previously selected text is put in the unnamed register (and
possibly the selection and/or clipboard).  This is useful if you want to put
that text somewhere else.  But you cannot repeat the same change.
With |P| the unnamed register is not changed (and neither the selection or
clipboard), you can repeat the same change.

Thus you can yiw to yank a word, then do multiple viwP replaces with that yanked word.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.