How can I set up vim in such a manner, that it spellchecks only the text portion of my file?

I write a lot of reports that include code listings, which I would like to exclude from the spellchecking.

Also I am writing in different languages: german and english. How do I setup vim to do the spell checking properly. Which spell-checking packages are the best (aspell/ispell/...)?

  • For readers: this a duplicate-ish of a similar question on StackOverflow stackoverflow.com/q/34301741/2954547. I have added an answer to that question covering Tree Sitter (for Neovim users) instead of the traditional Vim command highlighting. Jan 9, 2023 at 20:31

1 Answer 1


Vim has built in spell checking. You do not need external spell checkers. Simply use :set spell to enable spell checking.

To disable spell checking in code listings, you need to modify the vim syntax file for tex. Copy $VIMRUNTIME/syntax/tex.vim to $HOME/.vim/syntax/tex.vim. Around line 402, this file has:

syn region texZone      start="\\begin{verbatim}"           end="\\end{verbatim}\|%stopzone\>"  contains=@Spell
syn region texZone      start="\\begin{code}"               end="\\end{code}\|%stopzone\>"  contains=@Spell
" listings package:
syn region texZone      start="\\begin{lstlisting}"         end="\\end{lstlisting}\|%stopzone\>"    contains=@Spell
" moreverb package:
syn region texZone      start="\\begin{verbatimtab}"        end="\\end{verbatimtab}\|%stopzone\>"   contains=@Spell
syn region texZone      start="\\begin{verbatimwrite}"      end="\\end{verbatimwrite}\|%stopzone\>" contains=@Spell
syn region texZone      start="\\begin{boxedverbatim}"      end="\\end{boxedverbatim}\|%stopzone\>" contains=@Spell

Change each of these @Spell to @NoSpell and vim will not spell check in the respective environments.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .