Spellchecker Wrangling

I've been writing a whole lot of XML lately. Doesn't sound like fun, does it? Well, it's not all that bad, because I'm well-versed in working with XML in Vim.

One oddity you'll run into when editing XML is spell checking won't work as expected. This is partly because of how the XML syntax file is configured ($VIMRUNTIME/syntax/xml.vim). To force Vim to check spelling, you can run these commands:

:set spell
:syntax spell toplevel

Afterwards, press CTRL-l to redraw the screen so you can see any spelling mistakes. The last command basically forces spell checking in text where the syntax file hasn't defined any other behaviour. If you've got an XML file open, you should see spell checking in each element's content, but tags themselves will be ignored.

You could force it to check the spelling of tags if you wanted by adding @Spell to the syn match options:

syn match   xmlTagName
    \ +[<]\@<=[^ /!?<>"']\++
    \ contained
    \ contains=xmlNamespace,xmlAttribPunct,@xmlTagHook,@Spell
    \ display

Although this isn't particularly useful. If you want to ensure spelling isn't included for a given match, you can add @NoSpell to the options.

I found a good overview of how to beat xml.vim into submission in this StackOverflow answer: Vim is spellchecking files where I don't want it to.

blog comments powered by Disqus