Vim can help you autocomplete tags based on the supplied DTD. First you have to obtain the DTD definition file for the XML subset (such as DocBook) you want to use, the convert it to Vim compatible format, and the let Vim know which file to load.
Download the perlSGML package, unzip it, cd to the unpacked directory (
perlSGML.1997Sep18/
, run perl install.me, and answer to the questions.Download the DTD file you want to use with Vim. For example, DocBook5 DTD can be found at http://docbook.org/xml/5.0/dtd/docbook.dtd.
Download dtd2vim and run perl dtd2vim docbook.dtd docbook5. The script creates the
docbook5.vim
file.Move
docbook5.vim
to~/.vim/autoload/xml/docbook5.vim
.Restart Vim and open some DocBook file. To tell Vim to use the previously converted
docbook5.vim
file, set :XMLns docbook5 from within the Vim command mode.To have Vim autocomplete the tag for you, start typing it with the opening sharp bracket
<
- you can optionally add a few initial characters to make the suggestion list smaller - and then press the default omni-completion shortcut + + + . Vim offers you a list of possible choices. Select one and press>
to finish the tag.Tip
Because
+ + + is awkward, I suggest you to remap it in your~/.vimrc
to for example + adding the following lines for XML and DocBook file types:autocmd FileType xml,docbk imap <C-@> <C-X><C-O>
Then restart Vim and enjoy your wild editing experience :-)