Reselect pasted text
To paste text in Vim we use the p
mapping. This text text can come from another buffer, copied or “yanked” with y
, or it can come from another application on your system using the clipboard register.
But sometimes after pasting text, we might want to do some additional clean up on it. Perhaps, we want to perform some substitution, indent it, or align it. We can do any of these things if the text is visually selected again.
Instead of manually reselecting the text you just pasted, try adding this mapping to your .vimrc
:
" reselect pasted text
nnoremap gp `[v`]
Now you can use gp
to instantly reselect the text you just pasted. This pairs nicely with the native Vim mapping gv
, which reselects the last visual selection.
Check out the brief demo below. It it, I paste some text with p
then reselect it using my gp
mapping and then press =
to indent the selected text.