This question may have an obvious answer that I'm missing, but how can I easily tell how many of a character, in this case " , " are in a line, or a specified string using vimscript?
You can use this:
:echo len(split(getline('.'), ','))
That will get the content of the current line, split it on the
, (comma) to a list and count the number of items of the list.
Note: that the
count() function just relatively recently learned about counting items in strings, while this solution is also compatible with Vim 7.