简体   繁体   English

在光标下询问单词,用于在vim中拼写突出显示

[英]Interrogating word under cursor for spelling highlighting in vim

I've recently discovered the built-in spell checking of Vim. 我最近发现了Vim的内置拼写检查。 I noticed in the documentation that there were several classes of highlighted words that are revealed by activating spell checking (a la :setlocal spell spelllang=en_us ). 我在文档中注意到,通过激活拼写检查(la :setlocal spell spelllang=en_us )可以显示几类突出显示的单词。 These different classes show me different kinds of spelling errors, but it's not always clear to me which kind of error I've made just based on the color. 这些不同的类向我展示了不同类型的拼写错误,但我并不总是清楚我根据颜色做出了哪种错误。

I know that I can look at different spelling suggestions for the word using z= with my cursor over it, but I'd really like a similar command that just tells me what type of spelling error I've made. 我知道我可以使用z=查看单词的不同拼写建议,我的光标在它上面,但我真的很喜欢一个类似的命令,只是告诉我我犯了什么类型的拼写错误。

I also know that I could look at the list of different highlighting classes using :hi , but that's rather unwieldy. 我也知道我可以使用以下方法查看不同突出显示类的列表:hi ,但这相当笨拙。 I'd like to have a quick way of looking up the name of the class from the :hi table that is being applied to the text under the cursor. 我想快速查看正在应用于光标下文本的:hi表中的类名称。

The closest I've gotten is :echo synIDattr(synID(line("."),col("."),1),"name") , which gives me the syntactic context under the cursor. 我得到的最接近的是:echo synIDattr(synID(line("."),col("."),1),"name") ,它给出了光标下的句法上下文。 This doesn't actually tell me anything about spelling in any of the contexts I've tried. 在我试过的任何环境中,这实际上并没有告诉我有关拼写的任何信息。

I don't know a way to query the current word's type of spell error. 我不知道查询当前单词的拼写错误类型的方法。 Because I frequently forget which highlighting means what, I have defined this command to aid my memory: 因为我经常忘记哪个突出显示意味着什么,我已经定义了这个命令以帮助我的记忆:

function! s:SpellLegend()
    for [l:group, l:explanation] in [
    \   ['SpellBad', 'word not recognized'],
    \   ['SpellCap', 'word not capitalized'],
    \   ['SpellRare', 'rare word'],
    \   ['SpellLocal', 'wrong spelling for selected region']
    \]
        echo ''
        echon l:group . "\t"
        execute 'echohl' l:group
        echon 'xxx'
        echohl None
        echon "\t" . l:explanation
    endfor
endfunction
command! -bar SpellLegend call s:SpellLegend()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM