Thursday, July 21, 2011

Re: Installing a word count plugin -- or recommendations of other plugins

Am 21.07.2011 16:20, schrieb Eric Weir:
>
> I would like to have a word count plugin to replace the g<C-g>
> command. The results of the latter are displayed so briefly and
> amongst other details that it is hard to be certain what they are.
>
> I've found a "manuscript word count" plugin at vim.org. The creator
> explains that "Standard word count utilities (like unix 'wc') do not
> provide an accurate count because they count breaks between words. In
> fiction writing, some sentences--like this one--have more words than
> breaks between words."
>
> So it does what I want but there are no installation instructions and
> I'm not certain how to install it. I put it in ~/.vim/plugin and
> reloaded Vim but it does not work.
>
> Suggestions for getting the plugin to work would be appreciated.
>
> Likewise regarding alternatives to it and the built-in word count
> command.

I'd assume that a word count is supposed to count words ("word" as in :h
word), not WORDs. So here is a simple command you can put in the vimrc:


com! -bar -range=% WC call WordCount(<line1>,<line2>)

let g:wordcount_pat = '\k\+\%(''\k\+\)\='
" this counts "don't" as one word

func! WordCount(line1, line2)
let n_words = 0
for str in getline(a:line1, a:line2)
let n_words += len(split(str, g:wordcount_pat, 1))-1
endfor
echo "counted" n_words "words"
endfunc


(or the same as a one-liner)

com! -bar -range=% WC echo printf("counted %d words",
\ eval(join(map(getline(<line1>,<line2>),
\ 'len(split(v:val, g:wordcount_pat, 1))-1'), "+")))

--
Andy

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment