Fast word count function in Vim

后端 未结 16 2036
后悔当初
后悔当初 2020-12-08 00:27

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

16条回答
  •  [愿得一人]
    2020-12-08 01:10

    This is an improvement on Michael Dunn's version, caching the word count so even less processing is needed.

    function! WC()
        if &modified || !exists("b:wordcount") 
                let l:old_status = v:statusmsg  
                execute "silent normal g\"
                let b:wordcount = str2nr(split(v:statusmsg)[11])
                let v:statusmsg = l:old_status  
                return b:wordcount
        else
                return b:wordcount
        endif
    endfunction 
    

提交回复
热议问题