vim-airline/autoload/airline/extensions/wordcount.vim

36 lines
1.1 KiB
VimL
Raw Normal View History

2015-10-05 14:17:04 +00:00
" MIT License. Copyright (c) 2013-2015 Bailey Ling.
" vim: et ts=2 sts=2 sw=2
let g:airline#extensions#wordcount#filetypes = '\vhelp|markdown|rst|org'
" http://stackoverflow.com/questions/114431/fast-word-count-function-in-vim
function! airline#extensions#wordcount#count()
let old_status = v:statusmsg
let position = getpos(".")
exe "silent normal g\<c-g>"
let txt = ''
2015-10-05 14:17:04 +00:00
let stat = v:statusmsg
if stat != '--No lines in buffer--'
let parts = split(v:statusmsg)
if len(parts) > 11
let cnt = str2nr(split(v:statusmsg)[11])
let spc = g:airline_symbols.space
let txt = cnt . spc . 'words' . spc . g:airline_right_alt_sep . spc
endif
2015-10-05 14:17:04 +00:00
end
call setpos('.', position)
let v:statusmsg = old_status
return txt
2015-10-05 14:17:04 +00:00
endfunction
function! airline#extensions#wordcount#apply(...)
if &ft =~ g:airline#extensions#wordcount#filetypes
call airline#extensions#prepend_to_section('z', '%{airline#extensions#wordcount#count()}')
2015-10-05 14:17:04 +00:00
endif
endfunction
function! airline#extensions#wordcount#init(ext)
call a:ext.add_statusline_func('airline#extensions#wordcount#apply')
endfunction