本文介绍了Vim,单词频率功能和法语口音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发现了Vim Tip n°1531(文件的词频统计).

I have recently discovered the Vim Tip n° 1531 (Word frequency statistics for a file).

按照建议,我将以下代码放入.vimrc

As suggested I put the following code in my .vimrc

function! WordFrequency() range
  let all = split(join(getline(a:firstline, a:lastline)), '\A\+')
  let frequencies = {}
  for word in all
    let frequencies[word] = get(frequencies, word, 0) + 1
  endfor
  new
  setlocal buftype=nofile bufhidden=hide noswapfile tabstop=20
  for [key,value] in items(frequencies)
    call append('$', key."\t".value)
  endfor
  sort i
endfunction
command! -range=% WordFrequency <line1>,<line2>call WordFrequency()

除了口音和其他法语特征(拉丁小字母a或o等)之外,它都可以正常工作.

It works fine except for accents and other french specifics (latin small ligature a or o, etc…).

我应该在此函数中添加什么以使其适合我的需求?

What am I supposed to add in this function to make it suit my needs ?

预先感谢

推荐答案

对于8位字符,您可以尝试将拆分模式从\A\+更改为[^[:alpha:]]\+.

For 8-bit characters you can try to change the split pattern from \A\+ to[^[:alpha:]]\+.

这篇关于Vim,单词频率功能和法语口音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 02:43