Spell check XML files without VIM syntax problems
Mar 22, 2012
I've been using XMLMind's XML Editor lately to write some documentation in the Docbook XML format. The editor has very good support and I'm very glad to be using it. There's one catch though, and it's to do with the spell check support. XMLMind have implemented their own system for which there are no Greek dictionaries available. Not having the time to go and create one myself I looked at other solutions.
I have the Hunspell dictionaries on my system anyway but the command line program that comes with Hunspell garbles Greek characters in the terminal. I don't know what that's about and Google didn't come up with any quick solutions. So my next try was using spell check support in VIM 7 and after a bit of trial and error I'm happy with the result. So here's what I did:
- Download a Myspell compatible Greek dictionary word list and affix file, either the original one by Steve Stavropoulos or the one by Dimitrios Gianitsaros which combines the Greek words and English words as well as provides for Greek fully capitalized words with no accents.
:mkspell el /path/to/hunspell/dictionaries/el_GR
- make sure the resulting
.spl
file gets copied to~/.vim/spell
- create the file
~/.vim/after/syntax/xml.vim
as described below. - Open an XML file and execute
:set spell spelllang=el,en
or something to that effect.
One little problem with spell checking XML files in VIM is that the syntax highlighting interferes in a sub-optimal way. For example by default the text content of elements is not spell checked. Another example is that URL's in href
and xmlns
attributes are reported as mistakes. These problems can be solved by the following syntax commands:
syn match xmlHref +href="[^"]*"+ contained contains=xmlAttrib,@NoSpell syn match xmlXmlns +xmlns\(:[a-z]*\)\?="[^"]*"+ contained contains=xmlAttrib,@NoSpell syn cluster xmlStartTagHook add=xmlHref syn cluster xmlStartTagHook add=xmlXmlns syn spell toplevel
Now you should be good to go with spell checking XML in VIM. Another little detail about my work-flow is that I have configured gvim
as a helper application in XMLMind XML Editor and that permits me to type "Ctrl-Shift-D" while editing an XML file and get the file opened in VIM ready to be spell checked. After my corrections the file is reloaded in the XML editor.