G M
G M

Reputation: 22529

How to select multiple lines until a determinate character?

I would like to select multiple line until a determinate character, like in the image below where the special character is for this example is =.

enter image description here

I've tried with VIM ctrl+v/ but doesn't work.This is the example:

global Tint=spettro.readlines()[3].split(",")[1]
global Average=spettro.readlines()[4].split(",")[1]
global Sensor_Mode=spettro.readlines()[6].split(",")[1]
global Case_Temperature=spettro.readlines()[7].split(",")[1]
global Sensor_Temperature=spettro.readlines()[8].split(",")[1]

Upvotes: 1

Views: 1382

Answers (3)

jpkotta
jpkotta

Reputation: 9437

https://github.com/magnars/multiple-cursors.el

I haven't played with it much, but it can probably do what you want. Look at the video.

You can probably achieve your end goal with regex replacement (and maybe a keyboard macro), but you haven't stated what the end goal is. It's generally better to ask how to change one chunk of code into another, and not assume some technique (e.g. multiple selections).

Upvotes: 1

stefandtw
stefandtw

Reputation: 488

Try the vim-multiple-cursors plug-in.

Then, to select in those three lines:

  • /=<cr> go to the first '='
  • <c-n> start multiple cursors mode
  • <c-n> create a new cursor and jump to the second '='
  • <c-n> create a new cursor and jump to the third '='
  • ho0 select everything before the '='

Deleting and changing the selection seems to work fine. I do not know whether or not yanking is possible, too.

Upvotes: 1

Ingo Karkat
Ingo Karkat

Reputation: 172758

You can't in Vim. There's blockwise visual selection (via <C-V>), but this is restricted to rectangular blocks, expect for a selection (with $) that goes to the end of all covered lines, where a "jagged right edge" is possible.

Since selection in itself is of little value, you probably want to do something with it. There are alternatives, e.g. :substitute or :global commands with a pattern that selects up to the first =: /^[^=]*/

To yank the text, I'd use this (there are different approaches, too; note that you need to adapt the range inside the getline()):

:let @@ = join(map(getline(1, '$'), 'matchstr(v:val,"^[^=]*")'), "\n")

Upvotes: 2

Related Questions