3

With other editors we can select vertical-blocks where each line has the same start column but not the same end-column.

For example:

print("", s.field1);
print("", s.field_long);
print("", s.f);

Is there a way in Vim (with a plugin or not) to select the block from the snippet above:

field1
field_long
f

Can we tell vim to select everything up to a certain character?

A more powerful variant could be to tell Vim select everything between two characters going left and right from the currently selected column.

EDIT: Doing tricks with CTRL-v does not work as it always selected a rectangle. Here I vertically selected the fs and then did w for word-skip.

Patrick B.
  • 559
  • 1
  • 6
  • 16
  • 3
    This is not an exact duplicate, but you might be interested by my answer to this question: There are plugins which allows you to do what you want and there is probably a built-in feature which will allow you to do what you want but we would need more details on your final goal to help you efficiently. There is also <C-v>$y that you could use to yank the text you want to use followed by s:/);// to remove the unwanted characters. – statox Jun 03 '19 at 15:20
  • I use VSCode, and in insert mode I can do ctrl+shift+down ctrl+right arrow to do this. – Jeroen Vermunt Mar 20 '24 at 17:31

2 Answers2

1

Go to the first letter of the word, and press

<C-v>w

that selects the word. You may use

<C-v>5w

to select e.g. 5 words. Then you do whatever you want, e.g. to copy to clipboard you do

" * y
Kostas
  • 51
  • 3
0

If memory serves:

/field1<CR><C-v>2jf)
D. Ben Knoble
  • 26,070
  • 3
  • 29
  • 65