Fast word count function in Vim

后端 未结 16 2083
后悔当初
后悔当初 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:22

    Since vim version 7.4.1042

    Since vim version 7.4.1042, one can simply alter the statusline as follows:

    set statusline+=%{wordcount().words}\ words
    set laststatus=2    " enables the statusline.
    

    Word count in vim-airline

    Word count is provided standard by vim-airline for a number of file types, being at the time of writing: asciidoc, help, mail, markdown, org, rst, tex ,text

    If word count is not shown in the vim-airline, more often this is due to an unrecognised file type. For example, at least for now, the compound file type markdown.pandoc is not being recognised by vim-airline for word count. This can easily be remedied by amending the .vimrc as follows:

    let g:airline#extensions#wordcount#filetypes = '\vasciidoc|help|mail|markdown|markdown.pandoc|org|rst|tex|text'
    set laststatus=2    " enables vim-airline.
    

    The \v statement overrides the default g:airline#extensions#wordcount#filetypes variable. The last line ensures vim-airline is enabled.

    In case of doubt, the &filetype of an opened file is returned upon issuing the following command:

    :echo &filetype
    

    Here is a meta-example:

    vim-airline word count

提交回复
热议问题