问题
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