Question

How do calculate the number from inside the vim?

Was it helpful?

Solution

For counting the number of times some pattern occurs, use:

:%s/pattern//gn

OTHER TIPS

The following will work with unmodifiable files, and the result can be kept and used elsewhere in our scripts.

:let g:n = 0
:g/pattern/let g:n += 1
:echo g:n
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top