Spell check comments in vim

spell-checkingvim

I'm a C/C++ professional programmer who makes lots of spelling mistakes in comments. I want to configure vim such that the spell-checker only looks for misspelled words within comments. If necessary I'm willing to add special symbols around the comment that vim can look for to know where to check, such as:

 int main(){
     /*<--C_S 
        This is comment line in main function ..
        C_S-->*/
 }

If the plugin can work without the C_S symbols that'd be even better. I want the spell-checker to highlight any spelling mistakes it finds within comments. Does this already exist? Or is it easy to write myself?

Best Answer

Good news, this is already part of Vim. Turn on syntax highlighting (:syntax enable) and this should be taken care of automatically with the default syntax files packaged with any reasonably recent vim distribution. See :help spell-syntax for an explanation. The short version is that syntax files can use @Spell and @NoSpell to specify where spell checking should or should not occur.

Related Question