Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim spell checking filetype=tex files

Tags:

vim

My vim spell check does not properly when I open file ending in the suffix .tex.

If I have a text file called foo.txt and open that in vim and do :set spell, I get highlighting of misspelled words, I can move to them using ]s, etc, and I get get corrections options with z=. If I rename foo.txt to foo.tex and open it in vim, :set spell does nothing, ]s does nothing, but type z= when the cursor is on a word does provide correction options.

When I open foo.tex in vim, and do :set filetype, I get filetype=tex. If I instead do :set filetype=latex, the :set spell and ]s, etc., all work fine.

How do I get spell checking to work with .tex filetype files? Note, I just want spell checking to work when I explicitly do :set spell, I prefer it not to be on by default.

like image 632
mjandrews Avatar asked Sep 08 '25 03:09

mjandrews


1 Answers

The tex filetype specifies which syntax regions should be spell-checked, instead of letting the entire buffer be spell-checked. This is done to avoid the markup being flagged as misspelled when it shouldn't actually be spell-checked.

There are also a few variables that adjust which regions are spell-checked, as described in :help ft-tex-syntax:

                        *g:tex_nospell*
 Tex: No Spell Checking Wanted~

If you don't want spell checking anywhere in your LaTeX document, put >
    let g:tex_nospell=1
into your .vimrc.  If you merely wish to suppress spell checking inside
comments only, see |g:tex_comment_nospell|.

                *tex-nospell* *g:tex_comment_nospell*
 Tex: 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
If you want to suppress spell checking everywhere inside your LaTeX document,
see |g:tex_nospell|.

                *tex-verb* *g:tex_verbspell*
 Tex: Want Spell Checking in Verbatim Zones?~

Often verbatim regions are used for things like source code; seldom does
one want source code spell-checked.  However, for those of you who do
want your verbatim zones spell-checked, put the following in your <.vimrc>: >
    let g:tex_verbspell= 1

The reason it works when you set filetype=latex is because there is no latex filetype (unless you downloaded one). All the syntax rules for the tex filetype are cleared, and therefore the entire buffer is spell-checked, as is default when no syntax level spell-checking has been defined.

If you don't want the spell-checking to be restricted to specific syntax regions, you could add the following to ~/.vim/after/syntax/tex.vim

syntax spell toplevel
like image 130
jamessan Avatar answered Sep 10 '25 04:09

jamessan