Hi John!

On Di, 13 Okt 2009, John Beckett wrote:

> I am going to blame you for encouraging me to make a user
> command to run the code more easily. It is surprisingly sweet,
> although I definitely have to do some other stuff now, so I will
> leave testing the code as an exercise for the reader.
> 
> http://vim.wikia.com/wiki/Word_frequency_statistics_for_a_file

>From the Wiki:
>function! WordFrequency() range
>  execute a:firstline.','.a:lastline.'y'
>  new
>  setlocal buftype=nofile bufhidden=hide noswapfile
>  normal! Vp
>  %s/\_A\+/\t1\r/g
>  sort i
>  execute 'g/\c\(.\+\)\n\1$/normal! $yiwj@"'."\<C-A>kdd"
>endfunction
>command! -range=% WordFrequency <line1>,<line2>call WordFrequency()


That part here:
>  execute 'g/\c\(.\+\)\n\1$/normal! $yiwj@"'."\<C-A>kdd"
doesn't look right. I think you want at least:
   execute 'g/\c^\(.\+\)\n\1$/normal! $yiwj@"'."\<C-A>kdd"
(Note the anchoring of the pattern to the beginning of the line)

But other that that, this looks like an interesting approach, though 
somewhat obscure. I would change the function like this, which should be 
more clear:

function! WordFrequency1() range
  let a=[]
  let b={}
  let a=split(join(getline(a:firstline,a:lastline)),'\A\+')
  for word in a
    let b[word]=(exists("b[word]")?b[word]+1:1
  endfor
  new
  setlocal buftype=nofile bufhidden=hide noswapfile
  for [key,value] in items(b)
      call append('$',key.':'.value)
  endfor
  sort i
endfunction


regards,
Christian
-- 
:wq

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to