Multiple selections in VIM

Marcin picture Marcin · Oct 22, 2009 · Viewed 22.4k times · Source

Is it possible to select multiple non-consecutive lines (or sections) in VIM's visual mode? If so, how?

Answer

soulmerge picture soulmerge · Oct 22, 2009

No, this is not possible without plugins.

But you can copy multiple lines into the same buffer, if that solves your problem.

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