Vim: how to choose a nested block

Is there a vim command to directly select a block of text that has just been inserted?

ps. I know about gv to re-select a block after exiting visual mode. This does not apply to this case.

+6
vim
source share
1 answer

If you want to select it immediately after insertion (before changing anything else), use

 nnoremap <expr> gV "`[".getregtype(v:register)[0]."`]" 

. The values [ and ] indicate the beginning and end of the last change, v: the register is set to the last used register (which is the register used for the insert command, if you, for example, do not hold something), [0] selects only the first byte of the type case (required because for blockwise register it returns <Cv>{width} ), and the type of register is one byte, which is the same as a keystroke that you should use in normal mode to invoke visual mode.

I saw this solution somewhere on SO, you can look for it to get some alternatives.

+11
source share

All Articles