[Tutorial] Count the number of occurrences of a pattern in a file in Vim
Count the number of occurrences of a pattern in a file in Vim
:%s/pattern//gn
Explanation:
%is the range, which means the whole file.sis the substitute command.patternis the pattern to search.//is the replacement, which is empty in this case.gis the flag to replace all occurrences in a line.nis the flag to count the number of occurrences.