On Jan 9, 6:06 pm, Andy Wokula <[EMAIL PROTECTED]> wrote:
> I tried to write a function that collects all the matches for a given
> pattern in the text.
>
> For that purpose, it would be very nice if the following worked:
>     :%s/{pattern}/\=MyAddMatch(submatch(0))/gn


I agree, this could be easier.

Doing it with search() seems a bit tricky.

-it needs 2 calls to search()
-the startposition needs special care
  ( there could be a match in the first column of
    the first line one wants to search )

----------%<------------------
"Could be improved by handling the startpos differently
"and avoid the 3rd search.
func! CollectWords( pat, first_line, last_line )
  let result = []
  call cursor(a:first_line,1)
  while search(a:pat,'cW',a:last_line)
    normal! ms
    call search(a:pat,'ceW')
    normal! me
    normal! `sv`ey
    call add(result,@")
    call search('.','W')
  endwhile
  return result
endfun
----------%<------------------


Maybe someone has a better idea, apart from source modification.

-ap



--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui