将文件特定的好词添加到内部vim词表(通过modeline)


9

是否可以通过modeline将正确拼写的单词添加到vim的内部单词列表中?还是其他文件特定的方法?

Vim可以通过键盘命令zG或将单词添加到临时内部单词列表中:spellgood! {word}。可以对modeline做同样的事情吗?

一个例子是在下面的文本中,在使用vim的拼写检查时,我希望首字母缩写词“ RAS”和“ RAP”被视为好词。

RAS综合征(“冗余首字母缩写综合征”的缩写),也称为PNS综合征(“ PIN编号综合征”,扩展为“个人识别码编号综合征”)或RAP短语(“冗余首字母缩写短语”),术语“首字母缩写词”是指结合缩写形式使用构成首字母缩写词或首字母缩写词的一个或多个单词,因此实际上是重复一个或多个单词。

文本是从http://en.wikipedia.org/wiki/RAS_syndrome复制而来

Answers:


6

尽管我认为这是一个好主意,但Vim目前没有提供“本机”机制来执行此操作。我唯一想到的就是:autocmd调用一个函数,该函数搜索文件中的特殊部分,然后将光标移到该部分中的单词上并zG使用:normal命令触发。这将是一团糟,我不愿为此烦恼。

编辑:当然:spellgood!,即使您有问题,我还是以某种方式忽略了的存在。这使工作更加可行。我提出了一个基本的实现,您可以对其进行调整以满足您的需求:

function! AutoSpellGoodWords()
    let l:goodwords_start = search('\C-\*-SpellGoodWordsStart-\*-', 'wcn')
    let l:goodwords_end = search('\C-\*-SpellGoodWordsEnd-\*-', 'wcn')
    if l:goodwords_start == 0 || l:goodwords_end == 0
        return
    endif
    let l:lines = getline(l:goodwords_start + 1, l:goodwords_end - 1)
    let l:words = []
    call map(l:lines, "extend(l:words, split(v:val, '\\W\\+'))")
    for l:word in l:words
        silent execute ':spellgood! ' . l:word
    endfor
endfunction

autocmd BufReadPost * call AutoSpellGoodWords()

这将搜索如下所示的块:

-*-SpellGoodWordsStart-*-
word1 word2 word3
word4 word5 ...
-*-SpellGoodWordsEnd-*-

而且每个单词发现-在这种情况下,word1word2word3word4,和word5--within块将添加到临时好话名单。

请注意,我没有对此进行压力测试。


这比我预期的要深入,它将成为非常有用的vim脚本。我确实检查了vim.org,但没有任何类似的匹配项。谢谢!
Charles Maresh 2013年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.