Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any vim plugin that could restrict spell check only in comment in c source code file?

Tags:

vim

I'd like to turn on spell check to avoid typos in comment, but in code those red underlines are really annoying...

Some file type plugins could do that for other languages, like Python, but I couldn't find any c plugins.

I tried c.vim but it doesn't work.

like image 697
ablmf Avatar asked Jan 08 '12 04:01

ablmf


People also ask

Does Vim have spell check?

Using SpellcheckingTo 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 toggle spell check in Vim?

This is useful when editing text that also has Asian words. We can then press F11 to toggle spell checking.

How do I add spellcheck to Vim?

If you want to turn it on, run setlocal spell in the Vim command line (if you want spell check to always be on, add set spell to your . vimrc). After turning spell check on, misspelled words will now be highlighted. To move your cursor to the next misspelled word, enter ]s .

What is CSpell?

CSpell, a distributable spell checker for consumer language, is designed to detect and correct various types of spelling errors in Consumer Health Questions.


1 Answers

You should be able to modify the c syntax file to get the behavior you want. When you load a c file (or set a file to c filetype) the c syntax file is loaded from the /vimxx/syntax directory, it's the file there named c.vim. This file has all the various syntax statements that establish elements that can be highlighted.

You will notice several statements throughout the file that end with contains= and have @Spell among the groups that are "contained". If you remove @Spell from these statements (mostly string syntax items) and leave @Spell in the contains clause for "comment" elements (e.g., cComment) that should do what you want.

Be careful not to remove @Spell from any contains=ALLBUT, clauses, which, as you might guess, list syntax items that may not be contained in the given group.

like image 190
Herbert Sitz Avatar answered Sep 28 '22 02:09

Herbert Sitz