Fast word count function in Vim

Posted by Greg Sexton on Stack Overflow See other posts from Stack Overflow or by Greg Sexton
Published on 2008-09-22T11:58:22Z Indexed on 2010/05/08 23:18 UTC
Read the original article Hit count: 289

Filed under:

I am trying to display a live word count in the vim statusline. I do this by setting my status line in my .vimrc and inserting a function into it. The idea of this function is to return the number of words in the current buffer. This number is then displayed on the status line. This should work nicely as the statusline is updated at just about every possible opportunity so the count will always remain 'live'.

The problem is that the function I have currently defined is slow and so vim is obviously sluggish when it is used for all but the smallest files; due to this function being executed so frequently.

In summary, does anyone have a clever trick for producing a function that is blazingly fast at calculating the number of words in the current buffer and returning the result?

© Stack Overflow or respective owner

Related posts about vim