> Hi inthewild!
>
> On Do, 04 Jun 2009, [email protected] wrote:
>
>> does anybody know how to get the number of search results inside a
>> file?
>> Something like " NUMBER_OF_CURENT_RESULT ::
>> NUMBER_OF_TOTAL_OCCURRENCES" on statusline would be perfectly.
>
> I am not sure, I understand the difference between
> Number_of_current_result vs. Number_of_total_occurrences. But here is
> my proposal:
>
>
> func! CountSearch()
>     let cs=getpos('.')
>     redir => search
>     silent :%s//&/nge
>     redir END
>     call setpos('.', cs)
>
>     if search != ''
>         let s=split(substitute(search, '\n', '', ''), ' ')
>         let search=s[0] . '/' . s[3]
>     else
>         let search='0/0'
>     endif
>
>     return @/ . ': ' . search
> endfunc
>
>
>
> func! MyStl()
>     let stl='...'  " set you'r usual Statusline settings here
>     let sc=CountSearch()
>     return stl.sc
> endfunc
>
> set stl=%!MyStl()
>
> regards,
> Christian
> --  

thank you!
This correctly returns the the number of occurrences and the number  
of lines containing the search pattern.
By 'number_of_current_result' I mean the actual cursor position which  
becomes updated every time I jump to the next occurrence by pressing  
'n' in normal mode.

e.g.:   3 / 14
where 3 is the current_position and 14 the number_of_occurrences.
after pressing 'n' it would become '4 / 14' etc.

sincerely,
-- Dan

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

Reply via email to