Well I want to search for a string and find number of occurrences in a file opened using Vi editor.
What a better answer. +5 if possible
ojblass
2009-04-04 00:49:48
+7
A:
You need the n
flag. To count words use:
:%s/\i\+/&/gn
and a particular word:
:%s/the/&/gn
See count-items
documentation section.
If you simply type in:
%s/pattern/pattern/g
then the status line will give you the number of matches in vi as well.
dirkgently
2009-04-03 20:42:07
+4
A:
:g/xxxx/d
This will delete all the lines with pattern, and report how many deleted. Undo to get them back after.
Kevin Beck
2009-04-03 20:43:11
Of course, he can just omit the "d" so he doesn't have to unto the operation.
ldigas
2009-04-03 21:02:04
Note this only tells you how many lines - not how many occurences. I think dirk's is a better solution.
anon
2009-04-03 21:06:46
My solution below correctly counts multiple occurences within a line and there is nothing to undo.
Mohit Chakraborty
2009-04-03 21:14:48