3

First, I typed 2V to select two lines, and y to yank them. Then I typed 3V, and instead of selecting 3 lines, Vim selects 6 lines. Next I typed 4V and Vim selected 8 lines. It seems that 3 or 4 in the later selections are multiplied by the 2 in the first selection for yanking.

Why is that?

2

Although it seem counter intuitive, this behaviour seems to be the expected one. From :help V:

[count]V            Start Visual mode linewise.                                                                                                                                                                
                    With [count] select the same number of lines as used                                                                                                                                       
                    for the last Visual operation, but at the current                                                                                                                                          
                    cursor position, multiplied by [count].  When there                                                                                                                                        
                    was no previous Visual operation [count] lines are                                                                                                                                         
                    selected.
2

To be precise, [count]V select [count] * (lines of last visual operation) lines if and only if last visual operation is linewise (V).

In fact if last visual operation exists, [count]v, [count]V and [count]<c-v> are the same, they select [count] * (visual area of last visual operation) in the same wise mode with last visual operation.

If last visual operation doesn't exist, [count]v select [count]characters to right, [count]V select [count] lines down, [count]<c-v> select the same area with [count]v but in block wise.

2
  • Thanks. A question, what if I select and yank 3 lines, and then I want to select 4 lines, when 4 can't be [count] * 3? – Awe Some Jun 1 '19 at 2:03
  • 1vj or V3j. If you just want to yank 4 lines, use 4yy. – dedowsdi Jun 1 '19 at 2:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.