> > Hi vim_use! > > On Do, 04 Jun 2009, Christian Brabandt wrote: > >> >> Hi inthewild! >> >> On Do, 04 Jun 2009, [email protected] wrote: >> >>> 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. >> >> This simply checks, if the cursor is on the same line, as a match. >> I am not sure, if this is a clean solution, but it seems to work. >> Notice however it may slow down your vim considerably, if you use it >> on a long text with many matches. > > or faster, but will only show you, if the cursor is on or after a > certain match: > > func! CountSearch() > let cs=getpos('.') > try > redir => search > silent! :%s//&/nge > redir END > > redir => pos > silent! :1,.s//&/nge > redir END > catch > let search=0 > let pos=0 > endtry > > call setpos('.', cs) > > let search = substitute(search, '\n', '', '') > if search != '' && search != 0 > let search=split(search)[0] > else > let search=0 > endif > > let pos = substitute(pos, '\n', '', '') > if pos != '' && pos != 0 > let pos=split(pos)[0] > else > let pos=0 > endif > > call setpos('.', cs) > > return pos . '/' . search > endfunc
thank you very much! Although it doesn't return the correct number if there are many occurrences in one line it is already a considerable help for me. best regards, -- dan --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---
