Spell check comments in vim

8,507

Solution 1

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.

Solution 2

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.

Solution 3

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

Share:
8,507

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    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?

  • user4476006
    user4476006 over 7 years
    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.
  • Cecil Curry
    Cecil Curry over 7 years
    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.
  • Admin
    Admin almost 2 years
    This is the correct answer. There is no easy solution