Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to put word count on lightline? #295

Closed
alienbogart opened this issue Mar 17, 2018 · 5 comments
Closed

Is it possible to put word count on lightline? #295

alienbogart opened this issue Mar 17, 2018 · 5 comments

Comments

@alienbogart
Copy link

No description provided.

@itchyny
Copy link
Owner

itchyny commented Mar 17, 2018

I googled for word count vim and found a script https://gist.github.com/cormacrelf/d0bee254f5630b0e93c3. Example configuration using this function:

let g:lightline = {
      \ 'active': {
      \   'right': [ [ 'lineinfo' ], [ 'percent', 'wordcount' ], [ 'fileformat', 'fileencoding', 'filetype' ] ]
      \ },
      \ 'component_function': {
      \   'wordcount': 'WordCount',
      \ },
      \ }

@andreas-bulling
Copy link

Hi, I tried your solution but it doesn't work - nothing is shown in the statusline... Do I have to enable/do something else to make this work? Calling the WordCount function directly does work, though.

Thanks a lot!

@itchyny
Copy link
Owner

itchyny commented Apr 15, 2018

@andreas-bulling It works for me. Please paste your configuration or link to your vimrc.

@KargJonas
Copy link

Worked like a charm!
If you are having trouble with a separate file, just put the function directly into .vimrc

@MariusSwane
Copy link

The above script (in the link) works well, but if you are on newer versions of vim/neovim you can now use the following script to get selected words count and words 'so far'.

"new in vim 7.4.1042
let g:word_count=wordcount().words
function WordCount()
    if has_key(wordcount(),'visual_words')
        let g:word_count=wordcount().visual_words."/".wordcount().words " count selected words
    else
        let g:word_count=wordcount().cursor_words."/".wordcount().words " or shows words 'so far'
    endif
    return g:word_count
endfunction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants