How to disable spell highlight within a comment in Vim
Asked Answered
I

1

6

I type my LaTeX documents with Vim. I use both spell check and syntax highlight with the default plugins, although I use a customised colour scheme. With this setup, this is the typical view I get in LaTeX documents:

screenshot

As you can see, comments (otherwise green) are also highlighted in red by the spell checker. I'd like the comments to be fully green regardless of the syntax to facilitate the visualisation. How can I ask Vim to force the priority of comments highlight over syntax?

Implant answered 10/1, 2018 at 9:32 Comment(4)
have a look at :h syn-spell you can turn it of with @NoSpell in the syntax file.Indirection
Thanks for the hint, I fixed it. It turns out that the default syntax file is flexible enough to let the user decide how to behave in this regard. It works internally by defining the syntax with or without the @NoSpell attribute, depending on a global variable you can set. Therefore, including let g:tex_comment_nospell=1 in the filetype script produces the desired behaviour. Do you think I should promote this comment as a self-answer for the sake of completeness?Implant
Yes, please answer the question yourself; it might help other users in the future.Cranberry
Yes, definitly!Indirection
I
7

After the hint by Doctor OSwaldo, I followed the rabbit hole and figured out how to achieve the desired behaviour. It turns out that this is indeed supported by the standard syntax file for LaTeX and even well documented (see :h tex-nospel).

In short, you can define and set to 1 the global variable g:tex_comment_nospell to get the desired behaviour. Therefore, I only had to add let g:tex_comment_nospell=1 to my .vimrc.

Implant answered 10/1, 2018 at 15:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.