I know that vim has a function wordcount()
that returns a dictionary containing the number of bytes, lines, words etc in the current buffer. The problem I have is that the words
field of the dict from wordcount()
seems to include the number of WORD
s (vim's term for any sequence of chars that are not a whitespace character). For example, given:
# a markdown title
in a buffer, wordcount()['words']
returns 4, because the "#" counts as a word to vim. Is there some way I can count only the alphanumerical words in a buffer? I know I can use
:%s/\w\+//eng
but redirecting the output is cumbersome and slow if I want to have a constant word count (say, in the statusline). I need this for writing assignments.