Count number of matches of a pattern
From Vim Tips Wiki
created 2005 · complexity basic · author Marc Weber · version 7.0
To count the number of matches of a pattern, use the substitute command with the
n flag. The following shows the number of times that
pattern matches text in the current buffer:
g to display the number of lines where the pattern matches:
To restrict the count to a region of the text, specify a range instead of
% means all lines). For example, the following counts the number of occurrences in lines 10 to 50 inclusive:
The following counts the number of occurrences in the lines in the most recent visual selection.
 Word under cursor
To count the number of occurrences of the last used search pattern, you can leave out the pattern entirely:
This makes it easy to count the number of occurrences of the word under the cursor: first press
* to search for the current word, then enter
:%s///gn to count all occurrences of that word.