Exclude capitalized words from Vim Spell check

百般思念 提交于 2019-11-30 08:06:04

问题


There are too many acronyms and proper nouns to add to the dictionary. I would like any words that contains a capital letter to be excluded from spell checking. Words are delimited by either a while-space or special characters (i.e. non-alphabet) Is this possible?

The first part of the answer fails when the lowercase and special characters surround the capitalized word:

,jQuery,
, iPad,
/demoMRdogood/
[CSS](css)
`appendTo()`,

The current answer give false positives (excludes from the spellcheck) when the lowercase words are delimited by a special character. Here are the examples:

(async)
leetcode, eulerproject, 

The bounty is for the person who fixes this problem.


回答1:


You can try this one

:syn match myExCapitalWords +\<[A-Z]\w*\>+ contains=@NoSpell

The above command says vim to handle every pattern described by \<[A-Z]\w*\> as part of the @NoSpell cluster. Items of the @NoSpell cluster aren't spell checked.

If you further want to exclude all words from spell checking that contain at least one non-alphabetic character you can invoke the following command

:syn match myExNonWords +\<\p*[^A-Za-z \t]\p*\>+ contains=@NoSpell

Type :h spell-syntax for more information.




回答2:


Here is the solution that worked for me. This passes the cases I mentioned in the question:

syn match myExCapitalWords +\<\w*[A-Z]\K*\>+ contains=@NoSpell

Here is an alternative solution that uses \S instead of \K. The alternative solution excludes characters that are in the parenthesis and are preceded by a capitalized letter. Since it is more lenient, it works better for URLs:

syn match myExCapitalWords +\<\w*[A-Z]\S*\>+ contains=@NoSpell

Exclude "'s" from the spellcheck

s after an apostrophe is considered a misspelled letter regardless of the solution above. a quick solution is to add s to your dictionary or add a case for that:

syn match myExCapitalWords +\<\w*[A-Z]\K*\>\|'s+ contains=@NoSpell

This was not part the question, but this is a common case for spell checking process so I mentioned it here.



来源:https://stackoverflow.com/questions/18196399/exclude-capitalized-words-from-vim-spell-check

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!