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.
how about:
func! CountSearch()
let cs=getpos('.')
try
redir => search
silent! :%s//&/nge
redir END
catch
let search=0
endtry
call setpos('.', cs)
let search = substitute(search, '\n', '', '')
if search != '' && search != 0
let s=split(search, ' ')
let search=s[0]
else
let search=0
endif
let buffer = getline(1,line('$'))
let i=1
let pos=0
while match(buffer, @/, 0, i) != -1 && @/ != ''
let j = match(buffer, @/, 0, i)
if j + 1 == line('.')
let pos = i
break
endif
let i += 1
endwhile
return pos . '/' . search
endfunc
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.
regards,
Christian
--
:wq!
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---