Skip to content

Instantly share code, notes, and snippets.

@kmlawson
Created May 15, 2013 13:32
Show Gist options
  • Save kmlawson/5584008 to your computer and use it in GitHub Desktop.
Save kmlawson/5584008 to your computer and use it in GitHub Desktop.
Vimscript for a live word count. Mixed match code from stackoverflow and added check for empty file: http://stackoverflow.com/questions/114431/fast-word-count-function-in-vim
function! WC()
if getline(1) != ''
if &modified || !exists("b:wordcount")
let l:old_status = v:statusmsg
let position = getpos(".")
execute "silent normal g\<c-g>"
let b:wordcount = str2nr(split(v:statusmsg)[11])
let v:statusmsg = l:old_status
call setpos('.', position)
return b:wordcount
else
return b:wordcount
endif
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment