Is there a vim command to select pasted text?

One of your use cases is to change indentation after pasting.

I use the following maps to achieve this:

nnoremap <leader>[ `[V`]<
nnoremap <leader>] `[V`]>

They do the following:

  • de-indent the recently pasted block
  • indent the recently pasted block

I find these very useful and well used maps.


I prefer the following simple mapping to Benoit's function

nnoremap <expr> g<c-v> '`[' . strpart(getregtype(), 0, 1) . '`]'

Learn more about expression maps:

:h :map-expression

As @ZyX pointed out the strpart is not needed and can be rewritten as:

nnoremap <expr> g<c-v> '`[' . getregtype()[0] . '`]'

You are looking for

`[v`]

'[ and '] are marks automatically set by vim to the start and the end of the "previously changed or yanked text". v switches to visual mode in between.

Tags:

Vim