# How do I spellcheck TeX files using vim-lexical, skipping some command arguments but not others?

I use the vimtex plugin for TeX editing and vim-lexical for spell-checking.

This works generally fine, but there are several commands vim-lexical tries to spellcheck. For example, in \includepdf{pathToPdfFile} it marks the path to the file as spelling mistake. How can I tell vim-lexical that it should ignore everything in some commands (such as \includepdf) but consider in some others (everything in \bf should be checked)?

First: This is not related to vim-lexical. Syntax rules define where spell checking should be done, and so the current behaviour is defined by the internal syntax plugin for LaTeX.

The default syntax rule for tex command arguments allows spell checking. Some commands, e.g. \include{...}, are not spell checked. This is controlled by the @Spell and @NoSpell syntax clusters, see :h spell-syntax and :h syn-spell.

In order to add your own rules, you can create the file .vim/after/syntax/tex.vim. An example rule that will match \includepdf and prevent spelling is:

syntax match texInputFile /\\includepdf\%($.\{-}$\)\=\s*{.\{-}}/
\ contains=texStatement,texInputCurlies,texInputFileOpt


Note that this rule makes the syntax matching of \includepdf correspond to \include and similar commands. To prevent spelling of other commands where such a correspondence does not make sense, you could also use:

syntax match texStatement '\\includepdf' nextgroup=texMyNoSpell
syntax region texMyNoSpell matchgroup=Delimiter start='{' end='}' contained
\ contains=@NoSpell


Note: Please don't hesitate to open issues with vimtex for things like this. vimtex provides some updates to the syntax rules on top of the internal syntax plugin, and the \includepdf command is a good example of commands I personally think should be matched.

• Thanks. Maybe it's worth mentioning that it's actually not the fault of vimtex neither. Most of the syntax definitions come with vim and are located at /usr/share/vim/vim74/syntax/ (at least for ubuntu) – Jonas Feb 12 '16 at 11:48
• I think it is implied in the answer. I have already updated vimtex so that it fixes the spell checking for the \includepdf command. – Karl Yngve Lervåg Feb 12 '16 at 13:54