Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude capitalized words from spell checking in Vim?

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 whilespace or special characters (i.e., non-alphabetic characters). 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 gives 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.

like image 783
Forethinker Avatar asked Aug 12 '13 20:08

Forethinker


People also ask

How do I turn off spell check in Vim?

vim Spell checker Spell Checking To turn on the vim spell checker run :set spell . To turn it off run :set nospell .

How do I correct spelling in Vim?

Using Spellchecking To move to a misspelled word, use ]s and [s . The ]s command will move the cursor to the next misspelled word, the [s command will move the cursor back through the buffer to previous misspelled words. Just hit Enter if none of the suggestions work, or enter the number for the correct word.

How do I add words to dictionary in Vim?

To add words to your own word list: zg Add word under the cursor as a good word to the first name in 'spellfile'. A count may precede the command to indicate the entry in 'spellfile' to be used. A count of two uses the second entry. In Visual mode the selected characters are added as a word (including white space!).


1 Answers

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.

like image 161
user1146332 Avatar answered Oct 08 '22 10:10

user1146332