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?
1 Answer
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'
-
-
-
-
You are welcome :-) If it solve your problem don't forget to accept the solution. Oct 14, 2022 at 13:34
gv
will reselect your last selection.