Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to use Vim's builtin spellchecking in some XML documents. This happens merely by having the XML syntax loaded, as seen in the following minimalistic example (which reproduces what I also see in large XML documents):

spellchecking text but not xml

Note that given two buffers with exactly the same content, when Filetype is text, the spellchecking works; when it is xml, it does not. spell is set in both buffers.

However, given this view of the top three lines of a large XML document, you can see that the spellchecking is certainly on:

spellchecking working on attributes

but it is only checking attributes.

The nuisance is that none of the things it is actually finding are mispelled, and it isn't finding any of the numerous misspellings in the document. I would like it at a minimum to find the spelling errors in the body of the document, and being able to turn off the checking on attributes would be a nice option.

I've searched for @NoSpell in the xml.vim file, but that returns no hits.

share|improve this question
up vote 0 down vote accepted

This StackOverflow question contains a partial answer, which turned on the spellchecking in main body of the document. I put this in the part of my autocommands that initializes my XML files:

set spell
syntax spell toplevel
let &spellfile=$HOME . "/.xml." . &encoding . ".add"

The first command ensures the spelling is on. The second is the partial fix; the third sets a file such as /home/usr/.xml.utf-8.add as a file to save words added to the spelling dictionary for UTF-8 XML files.

Because I've made this file specific to XML files, if I'm not afraid of making that xsl will represent an actual misspelling elsewhere in the document, I could add that to the dictionary, etc; and thus it could be a full answer.

However, I found a better way to turn off spellchecking on attributes: changing the @Spell associated with attributes in xml.vim to @NoSpell (these lines are near the top of the file):

syn region  xmlString contained start=+"+ end=+"+ contains=xmlEntity,@NoSpell display
syn region  xmlString contained start=+'+ end=+'+ contains=xmlEntity,@NoSpell display

Together, these two sets of commands provide a full solution.


share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .