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

classic Classic list List threaded Threaded
38 messages Options
12
Reply | Threaded
Open this post in threaded view
|

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

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.

Thanks,
------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA  USA
[hidden email]




--
You received this message from the "vim_mac" 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
Reply | Threaded
Open this post in threaded view
|

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

David Henderson

On 21 Jul 2011, at 07:20, Eric Weir wrote:

> 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.

If this <http://www.vim.org/scripts/script.php?script_id=1191> is the script you’re writing about, then you’ve installed it correctly. If you were to launch MacVim from the terminal, you would see several lines of errors when the script tries to load. Based on one of those errors, I suspected that the issue was the end of line (eol) marker in the vim script. I opened the script in vim and issued the :set ff command which told me that the file was a DOS file; then, I issued :set ff=unix followed by :w. I relaunched MacVim, opened an essay, issued :WC, and received the expected output from the command. The problem was in the eol, the carriage return marker confused vim for example

line    4:
E492: Not an editor command: ^M
line    9:
E15: Invalid expression: !&cp && !exists(":WC") && has("user_commands")^M

note the ^M in the above, that is vim’s way of saying carriage return.

David P Henderson
c: 757.286.3212
--
"To announce that there must be no criticism of the president, or that we are to stand by the president, right or wrong, is not only unpatriotic and servile, but is morally treasonable to the American public."
    -- Theodore Roosevelt

--
You received this message from the "vim_mac" 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
Reply | Threaded
Open this post in threaded view
|

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

retiredff
In reply to this post by Eric Weir

On Jul 21, 2011, at 10:20 AM, Eric Weir wrote:


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.

Thanks,
------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA  USA
[hidden email]

Eric,

I use this for a word count function, the info is placed in my  
statusline:

let g:word_count="<???>"
function! WordCount()
     return g:word_count
endfunction

function! UpdateWordCount()
     let s = system("wc -w ".expand("%p"))
     let parts = split(s, ' ')
     if len(parts) > 1
         let g:word_count = parts[0]
     endif
endfunction

augroup WordCounter
     au! CursorHold * call UpdateWordCount()
     au! CursorHoldI * call UpdateWordCount()
augroup END

set statusline+=[wc:%{WordCount}]

OR

map <leader>F1 :echo 'wc:'WordCount()

If someone can improve on this, I would also be interested...
I would guess too many 'au' commands, tends to slow things down.

The above code displays EXACTLY the same number as :%s/[^ ]\+//gn
but more info (vim output example:) 1459 matches on 314 lines


TonyB

--
You received this message from the "vim_mac" 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

--
You received this message from the "vim_mac" 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
Reply | Threaded
Open this post in threaded view
|

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

PitPalme
In reply to this post by Eric Weir
Hi,

On Thu, Jul 21, 2011 at 16:20, Eric Weir <[hidden email]> wrote:
I've found a "manuscript word count" plugin at vim.org.

Next time it would be nice to have a final link to the objected resource included in your message, instead of possible responders first have to search.
In this case this would have been <url:http://www.vim.org/scripts/script.php?script_id=1191>

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."

How the h*** can you have more words than breaks between them? Ain't a word the thing between to non-word things?
Whatever ...
 
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.

That's right. And in "Konsole.app" one can see why:

org.vim.MacVim[7660]: Error detected while processing ~/.vim/plugin/wc.vim:
org.vim.MacVim[7660]: line    4:
org.vim.MacVim[7660]: E492: Not an editor command: ^M
org.vim.MacVim[7660]: line    9:
org.vim.MacVim[7660]: E15: Invalid expression: !&cp && !exists(":WC") && has("user_commands")^M
org.vim.MacVim[7660]: line   57:
org.vim.MacVim[7660]: E171: Missing :endif

This nice little "plugin" is obviously DOS-ed.
Solution:
- move the file "wc.vim" out of "~/.vim/.plugin", open it with "vim" or "MacVim".
- Execute ":set filetype=unix" and force a save.
- Quit vim/MacVim
- move "wc.vim" to "~/.vim/plugin"
- be happy

Honestly: a plugin author that does not know about different line ending styles does word count better than "wc" (which exists for aeons and nevertheless does wrong?)? I'm impressed. A little ...
-- 
Regards,

Peter

--
You received this message from the "vim_mac" 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
Reply | Threaded
Open this post in threaded view
|

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

PitPalme
*argh*

On Thu, Jul 21, 2011 at 17:22, I wrote:
[...]
> - Execute ":set filetype=unix" and force a save.

s/filetype/fileformat/g

Correct order: Think, check, write.
Wrong order: Think, mix thoughts, write, check :-(
Sorry for the confusion.
--
Peter

--
You received this message from the "vim_mac" 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
Reply | Threaded
Open this post in threaded view
|

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

Björn Winckler
In reply to this post by Eric Weir
Hi Eric,

I would like to ask you to please use the vim_use mailing list for general Vim questions instead of posting to vim_mac which is meant to be used for Mac-specific questions.  Of course, if you are in doubt as to whether a question is Mac-specific or not you are more than welcome to post to this list, but it seems to me that most of your questions so far clearly fall into the "general Vim questions" category.

Thanks,
Björn

On Jul 21, 2011, at 4:20 PM, Eric Weir wrote:

>
> 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.
>
> Thanks,
> ------------------------------------------------------------------------------------------
> Eric Weir
> Decatur, GA  USA
> [hidden email]
>
>
>
>
> --
> You received this message from the "vim_mac" 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

--
You received this message from the "vim_mac" 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
Reply | Threaded
Open this post in threaded view
|

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

Eric Weir

On Jul 21, 2011, at 11:31 AM, Björn Winckler wrote:

> I would like to ask you to please use the vim_use mailing list for general Vim questions instead of posting to vim_mac which is meant to be used for Mac-specific questions.  Of course, if you are in doubt as to whether a question is Mac-specific or not you are more than welcome to post to this list, but it seems to me that most of your questions so far clearly fall into the "general Vim questions" category.

No problem, Björn. I didn't understand the MacVim-specific purpose of vim_mac. I assumed it was simply "vim_use" for MacVim users. And you're right, probably all my requests for help have been general Vim requests. Thanks for letting me know.  

Sincerely,
------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA  USA
[hidden email]




--
You received this message from the "vim_mac" 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
Reply | Threaded
Open this post in threaded view
|

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

Eric Weir
In reply to this post by David Henderson

On Jul 21, 2011, at 11:15 AM, David Patrick Henderson wrote:

> If this <http://www.vim.org/scripts/script.php?script_id=1191> is the script you’re writing about, then you’ve installed it correctly. If you were to launch MacVim from the terminal, you would see several lines of errors when the script tries to load. Based on one of those errors, I suspected that the issue was the end of line (eol) marker in the vim script. I opened the script in vim and issued the :set ff command which told me that the file was a DOS file; then, I issued :set ff=unix followed by :w. I relaunched MacVim, opened an essay, issued :WC, and received the expected output from the command. The problem was in the eol, the carriage return marker confused vim for example

That was the plugin, David. Thanks for the diagnosis, explanation, and fix. Straightforward if you know what you're doing. I have no idea if as a script this plugin would be considered elegant. Near as I can tell it does what I want elegantly.

Thanks again,
------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA  USA
[hidden email]




--
You received this message from the "vim_mac" 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
Reply | Threaded
Open this post in threaded view
|

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

Eric Weir
In reply to this post by retiredff

On Jul 21, 2011, at 11:18 AM, Tony Berkopes wrote:

> I use this for a word count function, the info is placed in my statusline:

Thanks for sharing your script, Tony. With the diagnosis of the problem and the simple fix provided by David and Peter, I've decided to stick with the plugin I found on vim.org.

I really like the idea of having the count in the status line. I'm taking it your script doesn't continuously update the status line report? That would be even cooler.

Sincerely,
------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA  USA
[hidden email]




--
You received this message from the "vim_mac" 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
Reply | Threaded
Open this post in threaded view
|

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

Eric Weir
In reply to this post by PitPalme

On Jul 21, 2011, at 11:22 AM, Peter Palmreuther wrote:

Next time it would be nice to have a final link to the objected resource included in your message, instead of possible responders first have to search.
In this case this would have been <url:http://www.vim.org/scripts/script.php?script_id=1191>

My apologies, Peter. I'll make a point of that in the future.

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."

How the h*** can you have more words than breaks between them? Ain't a word the thing between to non-word things?
Whatever ...

How many words are in this pattern: "sentences--like"?
 
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.

That's right. And in "Konsole.app" one can see why:

Thanks for the diagnosis and solution. I'm not sufficiently conversant with Vim yet to have the sense to check that possibility. I learn by displaying my ignorance. 

Sincerely,
------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA  USA




--
You received this message from the "vim_mac" 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
Reply | Threaded
Open this post in threaded view
|

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

Eric Weir
In reply to this post by Eric Weir

On Jul 21, 2011, at 6:00 PM, Eric Weir wrote:

> On Jul 21, 2011, at 11:31 AM, Björn Winckler wrote:
>
>> I would like to ask you to please use the vim_use mailing list for general Vim questions instead of posting to vim_mac which is meant to be used for Mac-specific questions.  Of course, if you are in doubt as to whether a question is Mac-specific or not you are more than welcome to post to this list, but it seems to me that most of your questions so far clearly fall into the "general Vim questions" category.
>
> No problem, Björn. I didn't understand the MacVim-specific purpose of vim_mac. I assumed it was simply "vim_use" for MacVim users. And you're right, probably all my requests for help have been general Vim requests. Thanks for letting me know.  

Not to revise my response to your request, I just noticed that four of the five responses to my question were from vim_mac, including the only ones to diagnose the problem with the plugin that wasn't working.

Regards,
-----------------------------------------------------------------------------------------
Eric Weir
Decatur, GA  USA
[hidden email]




--
You received this message from the "vim_mac" 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
Reply | Threaded
Open this post in threaded view
|

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

retiredff
In reply to this post by Eric Weir

On Jul 21, 2011, at 6:21 PM, Eric Weir wrote:


On Jul 21, 2011, at 11:18 AM, Tony Berkopes wrote:

> I use this for a word count function, the info is placed in my  
> statusline:

Thanks for sharing your script, Tony. With the diagnosis of the  
problem and the simple fix provided by David and Peter, I've decided  
to stick with the plugin I found on vim.org.

I really like the idea of having the count in the status line. I'm  
taking it your script doesn't continuously update the status line  
report? That would be even cooler.

Sincerely,
------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA  USA
[hidden email]




--
You received this message from the "vim_mac" 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

Yes it does Eric.

I also found/downloaded the wc.vim script which can easily be made to  
update the statusline. It currently uses an 'echo' to output the  
results. I would guess, as I'm not by any means a vim expert, change  
it from 'echo' to 'return wc_count' then use the usual set statusline+=
\ [wc:%{wc}] should work. If I have time I will put the code from  
wc.vim into the code I posted earlier so the word count will be  
compliant with 'Strunk & White'(?).

TonyB


--
You received this message from the "vim_mac" 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
Reply | Threaded
Open this post in threaded view
|

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

Eric Weir

On Jul 22, 2011, at 5:41 AM, Tony Berkopes wrote:

> I also found/downloaded the wc.vim script which can easily be made to update the statusline. It currently uses an 'echo' to output the results. I would guess, as I'm not by any means a vim expert, change it from 'echo' to 'return wc_count' then use the usual set statusline+=\ [wc:%{wc}] should work. If I have time I will put the code from wc.vim into the code I posted earlier so the word count will be compliant with 'Strunk & White'(?).

Thanks, Tony. I'm not a programmer and am novice enough about Vim that I wouldn't be able to follow your suggestion for getting the output of wc.vim into the status line.

Curious why you would put the wc.vim code in your script. Again, in my naiveté, I imagine that would be redundant. If they do do the same thing, your's is so much simpler. [And therefor more elegant?]

Regards,
------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA  USA
[hidden email]




--
You received this message from the "vim_mac" 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
Reply | Threaded
Open this post in threaded view
|

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

retiredff
This post was updated on .
On Jul 22, 2011, at 7:52 AM, Eric Weir wrote:


On Jul 22, 2011, at 5:41 AM, Tony Berkopes wrote:

> I also found/downloaded the wc.vim script which can easily be made  
> to update the statusline. It currently uses an 'echo' to output the  
> results. I would guess, as I'm not by any means a vim expert, change  
> it from 'echo' to 'return wc_count' then use the usual set statusline
> +=\ [wc:%{wc}] should work. If I have time I will put the code from  
> wc.vim into the code I posted earlier so the word count will be  
> compliant with 'Strunk & White'(?).

Thanks, Tony. I'm not a programmer and am novice enough about Vim that  
I wouldn't be able to follow your suggestion for getting the output of  
wc.vim into the status line.

Curious why you would put the wc.vim code in your script. Again, in my  
naiveté, I imagine that would be redundant. If they do do the same  
thing, your's is so much simpler. [And therefor more elegant?]

Regards,
------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA  USA
eeweir@bellsouth.net




--
You received this message from the "vim_mac" 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

Eric,

As the wc.vim script states it is 'Strunk & White' compliant as to the  
EXACT number of words in a manuscript or other documents that must  
have an exact count. There IS a difference to the word count between  
the wc.vim and the other examples. I also have not determined which of  
the 2 is faster. Any comments from other readers is WELCOME!!

If you have read the code in wc.vim, I commented out the part that  
counts until a series of '--------' 8 dashes is found. I don't want/
need that and it probably slows it down for no reason.

Just copy/paste the example in a previous post into your .vimrc and  
add the example to your status line. Make sure it says set statusline
+= (don't forget to use the '+=', just '=' will remove any previous  
set statusline commands.

set statusline+=[wc:%{WordCount()}] will display something like  [wc:
1064] in your statusline.

OR, to use hot key and NOT in statusline

map <leader>F1 :echo 'wc:'WordCount()

I don't have the above code AND wc.vim loaded, as you have stated that  
would be redundant.

Hope this helps, TonyB

--
You received this message from the "vim_mac" 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
Reply | Threaded
Open this post in threaded view
|

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

Eric Weir

On Jul 22, 2011, at 9:32 AM, Tony Berkopes wrote:

> As the wc.vim script states it is 'Strunk & White' compliant as to the EXACT number of words in a manuscript or other documents that must have an exact count. There IS a difference to the word count between the wc.vim and the other examples. I also have not determined which of the 2 is faster. Any comments from other readers is WELCOME!!
>
> If you have read the code in wc.vim, I commented out the part that counts until a series of '--------' 8 dashes is found. I don't want/need that and it probably slows it down for no reason.
>
> Just copy/paste the example in a previous post into your .vimrc and add the example to your status line.

Thanks, Tony.

A little unclear what you're suggesting, though. When you speak of commenting out lines in wc.vim, it sounds like you're proposing retention of it for word count functionality.

When you speak of copying and pasting "the example in a previous post" into my .vimrc, it sounds like you're recommending replacing wc.vim with your script.

Or are you suggesting putting the wc.vim code in my .vimrc and incorporating the code for getting the count into the status line into it?

Is your script Strunk and White compliant?

Also, what is the command to run it?

Regards,
------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA  USA
[hidden email]




--
You received this message from the "vim_mac" 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
Reply | Threaded
Open this post in threaded view
|

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

retiredff
This post was updated on .
On Jul 22, 2011, at 1:26 PM, Eric Weir wrote:


On Jul 22, 2011, at 9:32 AM, Tony Berkopes wrote:

> As the wc.vim script states it is 'Strunk & White' compliant as to  
> the EXACT number of words in a manuscript or other documents that  
> must have an exact count. There IS a difference to the word count  
> between the wc.vim and the other examples. I also have not  
> determined which of the 2 is faster. Any comments from other readers  
> is WELCOME!!
>
> If you have read the code in wc.vim, I commented out the part that  
> counts until a series of '--------' 8 dashes is found. I don't want/
> need that and it probably slows it down for no reason.
>
> Just copy/paste the example in a previous post into your .vimrc and  
> add the example to your status line.

Thanks, Tony.

A little unclear what you're suggesting, though. When you speak of  
commenting out lines in wc.vim, it sounds like you're proposing  
retention of it for word count functionality.

When you speak of copying and pasting "the example in a previous post"  
into my .vimrc, it sounds like you're recommending replacing wc.vim  
with your script.

Or are you suggesting putting the wc.vim code in my .vimrc and  
incorporating the code for getting the count into the status line into  
it?

Is your script Strunk and White compliant?

Also, what is the command to run it?

Regards,
------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA  USA
eeweir@bellsouth.net




--
You received this message from the "vim_mac" 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

E,

In wc.vim there is a section of code that reads:

let n = wc_start_line
     while n <= wc_end_line
         let line = getline(n)
"         if match(line, "^--------") >= 0
"             let stop = " until '-------- found'"
"             break
"         endif
         let c = JCWC_line(line)
         let wc_count = wc_count + c
         let n = n + 1
     endwhile


the part commented OUT will read until it finds -------- OR 8 dashed  
lines in your file. These lines allow you to
find the word count of just a part of the file, maybe a paragraph or  
2. I don't need that and it probably slows things
down so I commented it out in wc.vim.

cut/paste this code to your .vimrc:

let g:word_count="<???>"
function! WordCount()
      return g:word_count
endfunction

function! UpdateWordCount()
      let s = system("wc -w ".expand("%p"))
      let parts = split(s, ' ')
      if len(parts) > 1
          let g:word_count = parts[0]
      endif
endfunction

augroup WordCounter
      au! CursorHold * call UpdateWordCount()
      au! CursorHoldI * call UpdateWordCount()
augroup END

ADD THIS to your statusline setting:

set statusline+=[wc:%{WordCount()}]

OR

nmap <leader>wc :echo 'wc:'WordCount()

then :so .vimrc<CR> -- this will reload .vimrc so the code will work.

the first pass will display <???> until it does the counting of each  
word. ON a large file, like eval.txt (help file)
it may take a second or 2. I have NOT timed the above code vs wc.vim.  
On the help file, wc.vim was slow but the output was 46k+ words, I  
have NOT tried the above code on the same file.


--
You received this message from the "vim_mac" 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
Reply | Threaded
Open this post in threaded view
|

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

Arthur Lee



cut/paste this code to your .vimrc:

let g:word_count="<???>"
function! WordCount()
return g:word_count
endfunction

function! UpdateWordCount()
let s D system("wc -w ".expand("%p"))
let parts = split(s, ' ')
if len(parts) > 1
let g:word_count = parts[0]
endif
endfunction

augroup WordCounter
au! CursorHold * call UpdateWordCount()
au! CursorHoldI * call UpdateWordCount()
augroup END

ADD THIS to your statusline setting:

set statusline+=[wc:%{WordCount}]

OR

nmap <leader>wc :echo 'wc:'WordCount()

then :so .vimrc<CR> -- this will reload .vimrc so the code will work.


It said:
E121: Undefined variable: WordCount   
-- 
Arthur Lee
Sent with Sparrow

--
You received this message from the "vim_mac" 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
Reply | Threaded
Open this post in threaded view
|

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

retiredff
This post was updated on .
On Jul 22, 2011, at 2:10 PM, Arthur Lee wrote:

>
>
>
> cut/paste this code to your .vimrc:
>
> let g:word_count="<???>"
> function! WordCount()
> return g:word_count
> endfunction
>
> function! UpdateWordCount()
> let s D system("wc -w ".expand("%p"))
> let parts = split(s, ' ')
> if len(parts) > 1
> let g:word_count = parts[0]
> endif
> endfunction
>
> augroup WordCounter
> au! CursorHold * call UpdateWordCount()
> au! CursorHoldI * call UpdateWordCount()
> augroup END
>
> ADD THIS to your statusline setting:
>
> set statusline+=[wc:%{WordCount()}]
>
> OR
>
> nmap <leader>wc :echo 'wc:'WordCount()
>
> then :so .vimrc<CR> -- this will reload .vimrc so the code will work.
>
>
It said:
        E121: Undefined variable: WordCount
--
Arthur Lee
Sent with Sparrow

--
You received this message from the "vim_mac" 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

Sorry!

The statusline should read  set statusline+=[wc:%{WordCount()}]

I forgot the '()' after WordCount.

I went back and edited any posts that were wrong...



--
You received this message from the "vim_mac" 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
Reply | Threaded
Open this post in threaded view
|

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

retiredff
Eric,

I ran a test using the code I posted WordCount() and the wc.vim plugin. I ran a test on vim's help file eval.txt because it is large!

I also commented out the part that looked for the 8 dashes '--------' because somewhere in the file wc.vim found that pattern. If that code was not commented out the results would have been different.

The results were surprising!

WordCount() found 49566 words

wc.vim found 49577.

WordCount is FAST! wc.vim is, well, NOT nearly as fast. It took maybe 2 seconds to display anything, WordCount is faster by far but less accurate. Does accuracy (11 words) matter to write code? I wouldn't think so, but for manuscript writers it may very well be. Use the one that fits your needs.
I will probably use WordCount() and keep wc.vim unloaded incase I need it.

Any code gurus that can speedup the wc.vim code?


TonyB
Reply | Threaded
Open this post in threaded view
|

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

Eric Weir

On Jul 22, 2011, at 8:43 PM, retiredff wrote:

> I ran a test using the code I posted WordCount() and the wc.vim plugin. I
> ran a test on vim's help file eval.txt because it is large!
>
> I also commented out the part that looked for the 8 dashes '--------'
> because somewhere in the file wc.vim found that pattern. If that code was
> not commented out the results would have been different.
>
> The results were surprising!
>
> WordCount() found 49566 words
>
> wc.vim found 49577.
>
> WordCount is FAST! wc.vim is, well, NOT nearly as fast. It took maybe 2
> seconds to display anything, WordCount is faster by far but less accurate.
> Does accuracy (11 words) matter to write code? I wouldn't think so, but for
> manuscript writers it may very well be. Use the one that fits your needs.
> I will probably use WordCount() and keep wc.vim unloaded incase I need it.

Thanks, Tony. I'll give your script a try. I will only ever need to do a word count on very small files or stretches of text, e.g., of between 500 and 3000 words. So most likely neither speed nor accuracy will be that critical. If it's in the ballpark count-wise that's good enough for me.

Of more interest is getting the output into the status line. A couple other things that would be cool: Having the word count constantly updated in the status line. Being able to do a word count on a selection. The latter would be genuinely useful.

One last question: Your code is short and simple. Nevertheless, could it be put into a vim file and used as a plugin instead of copying it into .vimrc?

Regards,
------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA  USA
[hidden email]




--
You received this message from the "vim_mac" 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
12