DTD Support

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.

  1. Download the perlSGML package, unzip it, cd to the unpacked directory (perlSGML.1997Sep18/, run perl install.me, and answer to the questions.

  2. 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.

  3. Download dtd2vim and run perl dtd2vim docbook.dtd docbook5. The script creates the docbook5.vim file.

  4. Move docbook5.vim to ~/.vim/autoload/xml/docbook5.vim.

  5. 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.

  6. 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 CTRL+x+CTRL+o. Vim offers you a list of possible choices. Select one and press > to finish the tag.

    Tip

    Because CTRL+x+CTRL+o is awkward, I suggest you to remap it in your ~/.vimrc to for example CTRL+SPACE 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 :-)