32864Re: put count into register
- Oct 2, 2002steve felt wrote:
>I think you want to use a variable, not a register.
> Hello, all!
> I would like to count things. I know that if I want to know how many of
> something there are, I can hack it with
> :%s/\(my favorite regex\)/\1/g
> the result:
> 65 substitutions on 23 lines
> However, when things are more complex, ie part of a script, how can I do
> this cleanly, for example:
> count the number of occurrences of regex x
> put the count into a register
> add to it the number of occurrences of regex y?
You might try the Count() function from foo.vim, quoted below.
This will find only one match per line, though. If you want to count all
matches, use a :while loop and the search() function.
HTH --Benji Fisher
let num = 0
execute 'g/' . a:pat . '/let num = num + 1'
- << Previous post in topic Next post in topic >>