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?
>
> Cheers,
> Richard.
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):
"function! FindMatchingRange()
function! FindMatchingLines()
let start = line('.')
let text = ''
for end in range(start, line('$'))
let text = text."\n".getline(end)
if text =~ @/
"return start.','.end
return text
endif
endfor
return ''
endfunction
You can use this either use it with :g command, or another function
:let matches=[]
:g/pattern/call add(matches, FindMatchingLines())
you can paste the matches in a new buffer as:
:call append('$', matches)
Read the help on |string-match| for limitations.
--
HTH,
Hari
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com