How to exclude capitalized words from spell checking in Vim?

You can try this command:

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

The above command instructs 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.


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.