0

I've seen a couple of questions about yanking and deleting a range of lines in Vim, for example, from line 5 to line 10.

However, I haven't found (in documentation and googling) about how to yank/delete in a single command, for example, lines 3, 5, 10 and 12.

Is this possible?

1

1 Answer 1

2

It's possible, but it's not simple. Vim does not support multiple ranges or multiple, non-adjacent line numbers. See

:help 10.3
:help :range

You could specify the lines to be yanked in the pattern of a :g command, though, using the line number atom. See

:help :g
:help /\%l

In the case of your example, the following would yank those lines into the a register.

:g/\%3l\|\%5l\|\%10l\|\%12l/y A
1
  • 2
    Note, for this to work as intended, the 'a' register must be empty. An easy way to do this, is to record an empty macro, by pressing qaq in normal mode.
    – Ben
    Apr 22, 2014 at 2:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .