How do calculate the number from inside the vim?
views:
84answers:
2
+9
A:
For counting the number of times some pattern occurs, use:
:%s/pattern//gn
vehomzzz
2009-10-23 14:21:50
+1 see :help count-items : An alternative is using |v_g_CTRL-G| in Visual mode.
Vereb
2009-10-23 14:31:03
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
2009-10-23 14:36:54
+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
2009-10-24 00:38:04