The syntax items within which Vim will highlight spelling mistakes are defined using the
@NoSpell clusters. See
:help spell-syntax (and the rest of the
:help spell and
:help syntax files) for full details.
The quick and dirty fix to get your desired result is to create a new file in your Vim config directory:
.vim/after/syntax/html.vim with the contents:
These lines define the syntax highlighting for HTML attributes, and were copied from the html.vim file that is included within Vim's standard syntax files. I then added the
@Spell cluster to the
contains field in order to enable spell-checking within each syntax item.
In order to apply this only to "title" and "data-*" attributes requires fine-tuning the regular expression used for matching the items, and slightly more extensive editing of the way HTML highlighting works. Here's a solution that works for "title" attributes only:
hi def link htmlStringSpell String
- The regular expression now includes the name of the
title attribute, and an offset so that this part of the syntax item is not included in the highlighting. (See
- The syntax item now has its own name, and therefore needs to (i) be
containedin all the syntax items that htmlStrings are contained in via their respective
contains settings. (ii) have its own highlighting applied.