0

Is there a way in VIM to visually select multiple sections / non-consecutive lines in a document that are not directly connected? My goal is to copy certain parts of a document to a different one, open on a different buffer in the current VIM instance. However the same procedure could also be used to delete such a selection. Let's say in the below example I want to select the rows 2,6 and 11.

1 global _main

2 extern _printf

3

4 section .text

5 _main:

6 push message

7 call _printf

8 add esp, 4

9 ret

10 message:

11 db 'Hello, World', 10, 0

Community
  • 1
  • 1
Eike
  • 451
  • 1
  • 4
  • 17
  • Sorry it it's sound like a digression to the original question which is explicitly vim focused, but for this kind of tasks involving non-connected multiple selections, Kakoune could be the right tool for the job. – Delapouite May 06 '20 at 09:11
  • 2
    Have a look here: https://stackoverflow.com/questions/1608204/multiple-selections-in-vim/16568663#16568663 – Andrea Baldini May 06 '20 at 09:12
  • Thank you @AndreaBaldini for finding the answer I was unsuccessful to find. The accumulation buffer concept that is in one of the answers is very workable for me. – Eike May 06 '20 at 09:36

1 Answers1

1

Thanks to @Andrea Baldini's higlight of a similar question I see one of the answers a workable solution for my problem that doesn't need any plugins. For reference I copy the response from @soulmerge

To start the 'Accumulation Buffer':
    1. mark a section to copy in visual mode,
    2. press "a to operate on the buffer a with the next command and
    3. yank it as usual (y).
To add to that buffer:
    1. mark the next section and
    2. press "A (capitalizing the buffer name means "do not overwrite the buffer, append to it instead")
    3. and yank again using y.
You can then paste the accumulated buffer a at any time using "ap.
Eike
  • 451
  • 1
  • 4
  • 17