Yakov Lerner wrote:
On 9/6/06, Elliot Shank <[EMAIL PROTECTED]> wrote:
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.

I think the point of the question was how to yank
multiple lines corresponding to multi-line pattern.
For single-line pattern, you're right, it's trivial.

Yakov


What about (untested)

:s/foo\_.{-}bar/\=(submatch(0) . nr2char(min([0, setreg(@", submatch(0), "c")])))

- execute it with the cursor on the line where the match starts
- all on one line
- the part after the dot is supposed to append the empty string to the "replace by" text while setting the unnamed register to the matched text

To put it into a separate document then:

        :new
        :0put "
        :wq


Best regards,
Tony.

Reply via email to