1

Sometimes I accidently put from the wrong register and end up hitting u to undo, but then I have to reselect the text that I was trying to replace. Is there an easy way to either reapply the put from the correct register or undo and restore the text that was previously selected?

2
  • gv will reselect your last selection.
    – paradroid
    Oct 13, 2022 at 4:04
  • 1
    @paradroid That looks like an answer to me!
    – Rich
    Oct 13, 2022 at 8:59

1 Answer 1

1

When you put the normal register are not modified apart from the " (and * if you are using clipboard unnamed setting) register that are replaced by the content that you override.

To avoid that behavior some use the mapping:

xnoremap p pgvy

It restores the content of the " to the value that has just been pasted.

A more advance version of this mapping does it only if you have used the " register to paste:

xnoremap <expr> p v:register=='"'?'pgvy':'p'
4
  • :help v_P in recent Vim
    – D. Ben Knoble
    Oct 13, 2022 at 12:41
  • Oh nice. This should be a default mapping.
    – paradroid
    Oct 14, 2022 at 10:57
  • O that is an interesting approach to it! Thanks for the tip. Oct 14, 2022 at 13:29
  • You are welcome :-) If it solve your problem don't forget to accept the solution. Oct 14, 2022 at 13:34

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.