Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In vim, how to visual select previously pasted text

Tags:

vim

I usually visual select a block and copy/cut it somewhere else, then I found myself always formatting the pasted text, so is there a way to quickly visually select the text again.

like image 588
Rn2dy Avatar asked Feb 09 '15 19:02

Rn2dy


1 Answers

Every command that modified the buffer (and yanks) will set the '[ and '] marks around the changed area. So you can reformat your pasted block via:

`[v`]=

Some people go so far as to use the following mapping to reselect last modified chunk of text:

nnoremap <expr> gV '`[' . getregtype()[0] . '`]'

With this mapping you can just do gV= and format your just pasted text.

However if you have the unimpaired.vim plugin and you are pasting linewise you can use the =p command it provides. This will paste and then reformat the text in one go. It also provides some other alternative paste commands >p for example will paste one indent level deeper.

like image 107
Peter Rincker Avatar answered Oct 08 '22 02:10

Peter Rincker