21

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?

21

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.

  • 1
    This only applies to buffers whose syntax files explicitly enable spell checking. Most, in my experience, do not. Since globally enabling spell checking is not necessarily a safe option, I typically extend Psirus' helpful answer with an augroup whose body resembles autocmd FileType md,rst,text,yaml setlocal spell spelllang=en_ca. See also the SPELLING subsection of this. – Cecil Curry Aug 12 '16 at 6:37
15

It already exists. Just type :set spell spelllang=en_us and it underlines spelling mistakes. Adjust the language to your needs. Additional languages can be found here.

1

As others said, it already exists. However, the rainbow plugin (default in spf13) will mess the spell check. It took me a while to figure it out.

The problem comes from the following line:

let def_rg = 'syn region %s matchgroup=%s containedin=%s contains=%s,@NoSpell %s'

rainbow incorrectly adds @NoSpell to all rainbow regions.

See https://github.com/luochen1990/rainbow/issues/30 for the details

  • 1
    Your answer would be much better if you took the effort to summarise the issue and how to fix it so that when the link dies, the essentials will still be present in your answer. – zagrimsan Aug 2 '16 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.