14.  Vim as XML Editor

If you do lot of XML editing with Vim, refer to this mini-howto on Vim as XML Editor at http://www.pinkjuice.com/howto/vimxml . See also Vim XML Wiki page , Devin Weaver "Script Karma" - xmledit a filetype plugin to help edit XML, HTML, and SGML documents, Vim.org XML scripts , Vim.org XML tips , w3.org - Well formed XML doc .

14.1.  Matchit.vim & Xmledit.vim

With XML syntax recognition turned on, you can find the matching XML tag by placing the cursor on the XML tag (but within the < and >) and then pressing the % key. Note, however that you should not place the cursor on the < or > since vim will simply match the < or > . Visit http://www.vim.org/scripts/script.php?script_id=39 For installation instructions enter:

vim somefile.txt
:help add-local-help
rpm -qa | grep -i vim
rpm -ql vim-minimal | less
rpm -ql vim-common | less
ls /usr/share/vim/vim61/macros/matchit.*
mkdir -p ~/.vim/plugin
cp /usr/share/vim/vim61/macros/matchit.vim ~/.vim/plugin/
mkdir ~/.vim/doc
cp /usr/share/vim/vim61/macros/matchit.txt ~/.vim/doc/
vim some-xml-file.xml  # And test out the % key to match the tags
      

For xmledit.vim download the tar ball from http://www.vim.org/scripts/script.php?script_id=301 and unpack this into ~/.vim for Unix and into $VIM/vimfiles folder for MS DOS or MS Windows.

	  cd ~/.vim
	  tar xvf xmledit.tar.gz
	  ln ftplugin/*.xml ~/.vim/plugin
	  vim some-xml-file.xml # And test out the autocreation of tags in insert mode
      

14.2.  Vim and Docbook - Useful key mappings

This is from Ashley - gVim and Docbook . One can write DocBook documents at an incredably faster rate if one maps element entry to key bindings. A directory called xml was created in the ftplugins directory of the gVim installation. Into this was placed a vim file that contained macros to map key combinations to element insertions. Comma preceeds each mapping, this is convenient because if the user types comma followed by space, nothing happens, but if the user types comma followed by one of the mapped key combinations an element is inserted. Most of the mappings are intuitive, for example, ulink is mapped onto ,-u-l. The mappings are very easy to customise and the improvement in document creation speed is amazing.

14.3.  XML Validation

To check for well-formedness of your XML document just do

:!xmllint --valid --noout %  
      

And the --dtdvalid dtd allows validation of the document(s) against a given DTD.