Vi(m) tip #4: word count in human files

Alec Jacobson

November 02, 2009

weblog/

I've begun writing my Nanowrimo novel in vim. To make sure I'm writing at least 1666.66666666666666666666667 words a day I'm constantly checking my word count. Here's one way to save (write) your file and check word count in a single command:
:w !wc -w
This of course assumes you are using vim on a unix/linux machine with the tool wc. Another way to count words is with only vi(m) functions:
:%s/[^ ]\+//gn
I prefer the first because the gsub method highlights every word in my document. Note: I get the same count for both of these. Any reason why I wouldn't? source