4

If you have the following text:

line 1
line 2
line 3

You can hit CTRL+v on line 1 and hit j to select line 2. However, I want to select both line 1 and line 3, but not line 2.

Or, select multiple arears like this: enter image description here

Is this possible?

5
  • 4
    this is not possible in Vim. Sep 23, 2020 at 18:10
  • Not sure what your final goal is, but Iselect may help. It lets you select lines and output them to a file. I have just found it and describe its basic usage here.
    – Quasímodo
    Sep 23, 2020 at 21:04
  • Are you sure you don't mean V to do a line-wise visual selection? <C-v> does a block-wise visual selection. Sep 23, 2020 at 21:57
  • 1
    What is your actual goal (post-selection)? :global/1\|3/ will let you run an action on only those two lines...
    – D. Ben Knoble
    Sep 23, 2020 at 22:31
  • Welcome to Vi and Vim!
    – filbranden
    Sep 23, 2020 at 22:55

2 Answers 2

4

From :h visual-use (emphasis mine):

Using Visual mode consists of three parts:

  1. Mark the start of the text with "v", "V" or CTRL-V. The character under the cursor will be used as the start.
  2. Move to the end of the text. The text from the start of the Visual mode up to and including the character under the cursor is highlighted.
  3. Type an operator command. The highlighted characters will be operated upon.

You cannot exclude certain portions. Visual mode will select all of the text between the start and end of the selection. The only caveat is that block-wise visual mode will select a rectangle of text, rather than line by line up to and including the cursor.

-1

If you're using vim on vscode, you can hold the option/alt key and click on the other line, it will put a cursor there, then you can shift + v it.

1
  • Welcome to this site, you can check the help center to have a better idea of what is on topic on this website. What you describe is a behavior of VS Code which doesn't exists in Vim so we usually don't mention them here. Thank you for participating anyway and I hope to see your future contributions on other questions :)
    – statox
    Mar 1, 2022 at 14:45

Your Answer

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

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