Loading ...
Sorry, an error occurred while loading the content.
 

Re: Re: Word count (continued)

Expand Messages
  • digitect@mindspring.com
    ... You re right, I mis-understood one of my tests. ... I like it, thanks! (I had tried a parsing of redirection from g/ /s//&/g but yours is many
    Message 1 of 4 , Apr 30, 2003
      on 4/30/2003 11:46 AM Benji Fisher said the following:
      > digitect@... wrote:
      > >
      > > writing a function that *returns* the number of words, reduced
      > > here:
      > >
      > > let @/ = '\<\w\+\>' | let cnt=0 | g//let cnt=cnt+1 | echo cnt
      > >
      > > except that this keeps returning the number of lines, not words.
      > >
      > > If I change @/ to equal 'myword' it returns the correct count,
      > > even if myword appears multiple times on the same line.
      >
      > I find that searching for 'myword' this way finds the number of
      > lines containing 'myword', not the number of copies of 'myword'.

      You're right, I mis-understood one of my tests.


      on 4/30/2003 12:23 PM Piet Delport said the following:
      >
      > What about:
      >
      > func WordCount()
      > exec "sil norm! g\<C-G>"
      > return matchstr(v:statusmsg, 'Word \d\+ of \zs\d\+')
      > endfunc

      I like it, thanks! (I had tried a parsing of redirection from
      'g/\<\w\+\>/s//&/g' but yours is many lines cleaner.)

      Not exactly sure how '\zs' is working though, particularly the 's'.


      --
      Steve Hall [ digitect@... ]

      Cream... the Vim text editor in sheep's clothing!
      http://cream.sourceforge.net
    Your message has been successfully submitted and would be delivered to recipients shortly.