Is there a way to tell vim not to spell-check part of a latex document?
For instance, code block using the minted
environment or URLs in \url{}
?
(I'm not sure it's relevant for spell checking but I'm using the vimtex plugin to edit latex files.)
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityIs there a way to tell vim not to spell-check part of a latex document?
For instance, code block using the minted
environment or URLs in \url{}
?
(I'm not sure it's relevant for spell checking but I'm using the vimtex plugin to edit latex files.)
You can disable spell checking for syntax items by adding them to a cluster together with @NoSpell
. You can read :help spell-syntax
for some information and look at your tex syntax file which most likely contains several examples already. If you type :tabe $VIMRUNTIME/syntax/tex.vim
you should get the tex syntax file in a new tab. If you then search /\c@NoSpell
you may see a line like
syn cluster texMathZoneGroup add=@NoSpell
The texMathZoneGroup
cluster has been defined earlier in the script to contain a number of syntax items and here @NoSpell
is added to the cluster to disable spell checking for these items. I'm afraid I can't say exactly where to best make the change for your particular syntax items as I don't know that syntax file very well. There may be an obvious cluster already where you can simply add @NoSpell
, or you may have to create a cluster that contains=
the items in question. It is also a good idea to make a copy of the syntax file in your user runtime directory and apply your changes there rather than change the distributed syntax file, or to apply your changes in a after/syntax/tex.vim
or other script that runs after the syntax file is loaded.
Since you use a plugin, it may have options related to which items are spell checked. I don't use vimtex
but Karl LervÄg is pretty active here and if you get his attention could answer that for you.
vimtex
today, no. But it seems to make sense to ignore spelling in minted environments, so I might update the plugin correspondingly. Thanks for the nice explanation!
– Karl Yngve Lervåg
Aug 26 '15 at 21:07
syn region mintedZone start="\\begin{minted}" end="\\end{minted}" contains=@NoSpell
but it doesn't seem to help. Any suggestion?
– Grégoire
Aug 27 '15 at 9:31
You can add your own syntax rules to e.g. ~/.vim/after/syntax/tex.vim
. In order to prevent spell checking inside a command such as \url
, you can use the following code:
syntax match texStatement '\\command' nextgroup=texMyCommand
syntax region texMyCommand matchgroup=Delimiter start='{' end='}' contained contains=@NoSpell
Here texStatement
and Delimiter
are groups that are defined by the internal syntax plugin, see :e $VIMRUNTIME/syntax/tex.vim
.
If you want to understand the above commands, I can recommend the following help sections: