Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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/...)?

share|improve this question
add comment

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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