I want to use visual block mode (ctl-v) to select all the comments but none of the code:

a = 1             // short comment
b = 2             // this one is a longer comment
c = 3             // shortest

My selection is marked with X characters here. Notice that if I start at the top-left my selection is unsatisfactory:

a = 1             XXXXXXXXXXXXXXXX
b = 2             XXXXXXXXXXXXXXXX longer comment
c = 3             XXXXXXXXXXX

If I start middle-left I lose either the first or third line:

a = 1             // short comment
c = 3             XXXXXXXXXXX

And so on. I'm missing something here. What is the secret? I've tried :help and searched here and Google.

2 Answers 2


The secret is to press $ after you have expanded your block vertically:


or to press $ before expanding your block vertically:


Well, $ is the secret.

…which is not that surprising, after all.


One (*) secret is:

set virtualedit=block

... in your vimrc :)

(:h virtualedit will explain everything).

A disadvantage of this method: when yanking, you get trailing spaces on the shorter lines.

(*) The other is in the answer provided by @romainl.

BTW, for the secret of the golden rivet, see this instead.

  • I've ticked @romainl but your answer was interesting too, and the clip :)
    – user251764
    Commented Aug 19, 2015 at 9:13
  • You chose well :)
    – VanLaser
    Commented Aug 19, 2015 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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