Hari Krishna Dara wrote:
On Wed, 6 Sep 2006 at 12:18pm, Druce, Richard wrote:
I'm trying to select all the text matching a (multi-line) pattern so I
can put it into a separate document. I thought the global command would
work but it only copies the first matching line, does anyone know a
command to do this?
I don't see any Vim primitives to work with multi-line matches. I think
the searchpos() function should be extended to return the [line, col] of
the end of the match as well. May be I am missing something, but in the
absence of primitives, you can probably write a function which will
try to guess what the matching lines are, something like this (only
partly tested):
None of this is necessary. The simple solution is to use the uppercase name of
a register, which appends to the register, rather than the lower case version,
which replaces.
For example, the "A" register is identical to the "a" register, but what you put into "A"
adds to "a", instead of replacing it. So, you want:
:g/foobie bletch/y A
After this, register "a" will contain every line that has "foobie bletch" in
it. However, it also contains whatever was in it previously, so make sure the register you use is
empty first.
The uppercase registers are really useful for moving arbitrary chunks of code to a combined
destination. Find the first set of lines you want to move and delete them into a lower-case
register, e.g. "r5dd. Then, go and find the other lines you want and use the upper-case
register, e.g. "R32dd. Finally, go to your destination and paste either register, e.g.
"rp.