I was reading this section:
:h count-items
To count how often any pattern occurs in the current buffer use the substitute
command and add the 'n' flag to avoid the substitution. The reported number
of substitutions is the number of items.
:%s/./&/gn characters
For the substitute function, it looks like only 'g' is supported
:h substitute()
When {flags} is "g", all matches of {pat} in {expr} are
replaced. Otherwise {flags} should be "".
It would be nice if substitute also allowed the 'n' flag.
And in that case, do not return the string, but return the count.
For example:
echo substitute('dadada', 'd', '&', 'g')
dadada
echo substitute('dadada', 'd', '&', 'gn')
3
Since the 'n' switch says "do not perform the sub" it seems reasonable
we could get something useful back.
Dave