Auto-completing XML Entities

If your XML entities are included in the file you are just editing, Vim can auto-complete their names for you - just write the initial& and press the omni-completion shortcut (CTRL+SPACE if you followed me recently).

If XML entities are included from other file, Vim cannot see it. You have to convert the entity file into .vim format and include it into the vimxmlentities option in the current Vim DTD file, such as ~/.vim/autoload/xml/docbook5.vim.

To ease this process, I included the update_docbook_entities.pl script. It takes your custom entity file as a first argument, and the DTD .vim file as a second argument. It extracts found entities, converts them into Vim understandable format, and adds them into the custom DTD file, such as docbook5.vim.

To add a shortcut to this script to Vim, add (and customized) this line to your .vimrc file:

nnoremap <silent> _e :!update_docbook_entities.pl xml/entity-decl.ent ~/.vim/autoload/xml/docbook5.vim<CR><CR>

This line ensures—assuming that you moved update_docbook_entities.pl to $PATH—that after pressing _e, the entities found in the xml/entity-decl.ent file will be added to ~/.vim/autoload/xml/docbook5.vim.