tags:

views:

84

answers:

2

How do calculate the number from inside the vim?

+9  A: 

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

:%s/pattern//gn
vehomzzz
+1 see :help count-items : An alternative is using |v_g_CTRL-G| in Visual mode.
Vereb
I generally still use this way if you forget the "n", you still don't affect your file (yes, I know you can just undo it).
Jefromi
+2  A: 

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
Luc Hermitte