Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Vim, why does V select more lines after yanking?

Tags:

vim

The first time I use 2V, Vim selects 2 lines in a visual block, as I would expect. When I clear the selection and do 2V again, it again selects 2 lines. Cool.

But when I do 2V, then yank with y, the next 2V will select 4 lines. If I keep alternating between 2V and y, the 2V will double the number of lines selected each time.

Why does this happen? I'm assuming it has something to do with registers, but I can't find a straight answer... why would the contents of a register affect V?

like image 260
Daniel Avatar asked Oct 21 '22 04:10

Daniel


1 Answers

This is special behavior in vim. It is documented in the help:

If Visual mode is not active and the "v", "V" or CTRL-V is preceded with a count, the size of the previously highlighted area is used for a start. You can then move the end of the highlighted area and give an operator. The type of the old area is used (character, line or blockwise).

  • Linewise Visual mode: The number of lines is multiplied with the count.
like image 107
Vaughn Cato Avatar answered Dec 13 '22 10:12

Vaughn Cato