Friday, June 25, 2010

Re: 1) Serach in the current file for all the match of regular expression X. 2) Insert at the cursor's current position the matches just founded.

Hi,

Robbo wrote:
>
> I need to write a command that acts as following:
>
> 1) Serach in the current file for all the match of regular expression
> X.
> 2) Insert at the cursor's current position the matches just founded.
>
> Could you give me some hints?

if you need only the first match in each line the following will work:

put =map(filter(getline(1, '$'), 'match(v:val, ''your-pattern'') > -1'), 'matchstr(v:val, ''your-pattern'')')

getline(1, '$') retrieves the content of the current file as a list. This
list is filtered agains your pattern with

'match(v:val, ''your-pattern'') > -1'

The result of filter() is again a list of lines. Each of those lines is
replaced by the result of

matchstr(v:val, ''your-pattern'')

leaving you with a list of the first matches in all lines.

Regards,
Jürgen


--
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us. (Calvin)

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment