How can I tell Vim's spell checker to ignore words which have a leading capital?
It's annoying that, for example, MyWidget
is flagged as a spellin开发者_如何转开发g error.
You can define a syntax element to ignore spell checking.
" Ignore CamelCase words when spell checking
fun! IgnoreCamelCaseSpell()
syn match CamelCase /\<[A-Z][a-z]\+[A-Z].\{-}\>/ contains=@NoSpell transparent
syn cluster Spell add=CamelCase
endfun
autocmd BufRead,BufNewFile * :call IgnoreCamelCaseSpell()
Note that the autocmd
is necessary to make sure that the syntax rules are loaded after the syntax definitions for the file type have been loaded (as the syntax rules wipe out any existing syntax rules).
However I'll personally prefer to add them (with zg
) as good, so I can check there is no typo rather than ignoring everything.
There is a patch available for vim that adds this functionality https://github.com/btucker-MPCData/vim/commit/8801705b7a4a64db39de65ea56e982132488ebde Showing the 'Spelng' part of the token is incorrect
Was also recently searching for good solution on smart spell check for vim/nvim. The best seems to be the coc-spell-check(https://github.com/iamcco/coc-spell-checker) after comparing with other plugins.
It basically gives you same experience as vscode's spell check. The exception words list is typically stored under ~/.config/nvim/coc-settings.json
's cSpell.userWords
object.
Just add MyWidget and all the other class names into your personal dictionary. Lookup vim help file to find out the personal dictionary name. Automate this away into a script.
精彩评论