5

It seems that spell-checking in vim is normally enabled at a buffer level (set spell vs. set nospell). However, sometimes it would be useful to ignore certain parts of a buffer (for example, URLs in text files often contain "nonsense" from a dictionary perspective, but are nevertheless valid and correct).

Is it possible to use the spell-checking support in vim only for parts of a buffer? For example, can one define regexes to ignore? Alternatively, are there any third-party spellcheckers for vim which can do this?

1

1 Answer 1

7

You can define syntax rule with the @NoSpell keyword. From :help :syn-spell

:sy[ntax] spell [toplevel | notoplevel | default]
        This defines where spell checking is to be done for text that is not
        in a syntax item:

        toplevel:       Text is spell checked.
        notoplevel:     Text is not spell checked.
        default:        When there is a @Spell cluster no spell checking.

        For text in syntax items use the @Spell and @NoSpell clusters
        spell-syntax.  When there is no @Spell and no @NoSpell cluster then
        spell checking is done for "default" and "toplevel".

        To activate spell checking the 'spell' option must be set.

For example, to not spell URLs, you could use something like:

:syn match url /\(\s\|^\s*\*\?\)\@<=\(http\|https\|ftp\):\/\/[-0-9a-zA-Z_?&=+#%/.!':;@~]\+/ contains=@NoSpell

Many syntax files use this. To the best of my knowledge this is the only way to tell the Vim spell checker to ignore certain parts.

1
  • 1
    OK, thanks, I didn't know that. Does that mean (to use my example) that I'd have to modify the standard vim syntax file for text files? Or can I put this in my .vimrc somehow to modify an existing set of syntax rules? Dec 17, 2015 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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