vim spell checking - comments only in LaTeX files
Solution 1
The latex ft plugin conveniently defines this behaviour.
SpellChecker : Spell check text including LaTeX documents
Using latexmk, vim spell checking and vim latex-suite
There is an option that appears to come close:
:syntax spell [toplevel | notoplevel | default]
Update
Also
:he ft-tex-syntax
has very useful tidbits, like
Don't Want Spell Checking In Comments? ~
Some folks like to include things like source code in comments and so would
prefer that spell checking be disabled in comments in LaTeX files. To do
this, put the following in your <.vimrc>: >
let g:tex_comment_nospell= 1
You'll have to figure out whether you can use that/extrapolate from there
Solution 2
I had the same problem (VIM 7.3), but this post at the vim-latex-devel mailing list provided the clue. To get the spell checking working, I had to put
syntax spell toplevel
in my ~/.vimrc
, but it has to be declared after
syntax enable
or
syntax on
for it to work.
Solution 3
I don't whether this is a crude hack and the intended solution, but I created a file called .vim/after/syntax/tex.vim containing the single line:
syn match texText "\<\w\+\>" contains=@Spell
Now vim spell checks the normal text between the commands and the text passed as parameters, because you cannot differentiate them syntacticly:
\frametitle{TextToBeChecked}
\pgfuseimage{VariableNotToBeChecked}
Hence, it checks way too much in my preamble. But I have it located in another file, so I don't really care.
Solution 4
This problem often occurs when working with files which are included by a master document.
If you are opening a TeX file which will be included and does not contain a section, chapter, \begin{document}
, ... you can mark it by adding %begin-include
at the top of the file. This way vim recognizes the file content as being part of the texDocZone
region, which enables spellchecking.
With %end-include
you can set the end of the texDocZone
.
This behavior seems not to be documented, but is described in the vim syntax file: https://github.com/vim/vim/blob/master/runtime/syntax/tex.vim
tl;dr: Add %begin-include
to the top of your tex file.
Jakub M.
Updated on June 07, 2022Comments
-
Jakub M. almost 2 years
I use gvim to edit LaTex .tex file. I noticed that it checks spelling on the fly only for the commented text. If I have a mistake in a regular text - no underline. If I comment this text with % , the misspell is underlined immediately. What is wrong? Is there any strange option turned on?