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


3 Answers 3


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.

  • There are no such options in 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! Commented Aug 26, 2015 at 21:07
  • I looked around in the code and I didn't find an existing region for minted environment so I tried to create my own like this: syn region mintedZone start="\\begin{minted}" end="\\end{minted}" contains=@NoSpell but it doesn't seem to help. Any suggestion?
    – Grégoire
    Commented Aug 27, 2015 at 9:31
  • @Grégoire Please, let us continue this discussion in the vimtex issue. Commented Aug 28, 2015 at 18:22

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:

  • Hi @Karl, thanks I have been using this. Is there a way to do this for an indeterminant number of repetitions of texMyCommand? Some commands can be \command{stuff} or \command{stuff}{morestuff}. I want to also ignore morestuff and as many more that come after. I haven't been able to find this in the syntax helpfiles in vim.
    – Paul
    Commented Aug 17, 2022 at 9:13
  • 1
    Figured it out. I used end='}^[{]` to exclude a } followed immediately by { to end the region.
    – Paul
    Commented Aug 17, 2022 at 9:19
  • You could do syntax region texMyCommand matchgroup=Delimiter start='{' end='}' contained contains=@NoSpell nextgroup=texMyCommand. But notice that this is greedy, which may not always be what you want. Commented Aug 18, 2022 at 10:21

For commands you can set g:vimtex_syntax_nospell_commands to a list of commands whose argument should be excluded from spell checking.

For example, I have set mine this way:

let g:vimtex_syntax_nospell_commands = ['foreign', 'posscite', 'toadd', 'todo', 'fontspec', 'Cref']

See :h g:vimtex_syntax_nospell_commands for documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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