Vim as XML Editor: About

... this howto.


The pages can be navigated via keys:

Access Keys


next page


previous page


index page

For example in NN6+/Mozilla, use [alt-n] to go to the next page, and [alt-p] to come back. In other browsers such as IE6, the access keys just give focus to the associated link, so the sequence becomes [alt-n] [enter].


Most importantly, you should be familiar with Vim. If that's not the case, check out the next section and come back in a few days.

Learning Vim

Teaching Vim is outside of the scope of this howto. Here are some resources, ranging from basic to advanced:
  • First you should make sure that you have the latest version of Vim. I recommend to use a GUI version of Vim, unless you're in a remote shell session.
  • Vim comes with a tutorial. After firing up Vim, enter :help tutor. One way to start with it is to read it into the buffer
    :read $VIMRUNTIME/tutor/tutor
    optionally delete the first line via g g d d, then write it to some file
    :write del/vim_tutorial.txt
  • Vim comes with lots of documentation which you can consult while working with Vim. Simply enter :help.
  • More documentation including the FAQ is listed on the Vim website.


All instructions are just examples, TMTOWTDI. For example: To move the cursor upwards I use [up], others use k.


Key sequences to be entered in Vim are written like this: 2 G [ctrl-v] [down] x. All commands are to be entered in normal mode. Insert mode commands start with an i, command line ones start with a :. Longer commands that are to be entered in Vim's command line are written like this:

In key sequences like this one [mapleader] x i < c h a p t e r > > [up] each group of non-space characters stands for one key press. If a space is to be entered it is listed as [space].

Vim commands and option names most often have a full and an abbreviated version. When using Vim I use the short versions, eg :h for :help, :w for :write, :q for :quit, etc. In the howto I sometimes use the full versions because they explain themselves better.

Mappings in Vi can be specified to start with <Leader>, which is a variable that can be set in the vimrc; see :help mapleader. If you did set your mapleader to some character other than the default (\), use this character instead wherever [mapleader] is written.

I don't use the notation used in Vim scripts because I think it's not very descriptive. If you want to use some of the commands in your Vim scripts, you must translate the function keys, eg [enter] to <CR> and [backspace] to <BS>.

Code that's to be entered in the shell of the OS most often is listed like this:
$ cd foo
The prompt character $ may indicate that the command is Linux-specific, and a > before a command may mean that the command is Windows-specific (to be entered in the "MS-DOS Prompt"). If there is no prompt character the command should work on at least both OSs.


"Linux" most often stands for Unix-like systems such as GNU/Linux, BSD, etc.

Installation on Linux


The Vim download page contains instructions and offers various formats.

If your distro came with sample files containing Vim settings you might want to disable them, eg by appending .bak to their name or by moving them to some backup directory. :version lists these files.

If you want additional features you might have to compile Vim yourself, check the README and INSTALL files. Here's a shortened version of how I installed it (after having resolved some dependencies such as termcap, ncurses-devel, XFree86-devel, pkgconfig).
$ wget -q \
$ tar -xjf vim-6.3.tar.bz2
$ cd vim63/
$ ./configure \
> --prefix=$HOME/bulk/run/vim/6_3 \
> --with-features=big \
> --enable-gui=gtk2 \
> --enable-rubyinterp \
> 2>&1 | tee > config.log
$ make 2>&1 | tee > make.log
$ make test 2>&1 | tee > test.log
$ make install 2>&1 | tee > install.log
$ ed
#!/usr/bin/env sh
${HOME}/bulk/run/vim/6_3/bin/vim "$@"
w /home/tobi/data/commands/vim
$ ed
#!/usr/bin/env sh
${HOME}/bulk/run/vim/6_3/bin/gvim "$@"
w /home/tobi/data/commands/gvim
$ chmod 700 ~/data/commands/vim
$ chmod 700 ~/data/commands/gvim
$ vim --version | head -n 3
VIM - Vi IMproved 6.3 (2004 June 7, compiled Jun 10 2004 15:19:15)
Big version with GTK2 GUI.  Features included (+) or not (-):
$ ed ~/.bashrc
export EDITOR='/usr/bin/vim'
export EDITOR='/home/tobi/data/commands/vim'
$ rpm -v --test --erase gvim
$ rpm -v --test --erase kvim
$ su root
# rpm -v --erase gvim
# rpm -v --erase kvim
# rpm -v --test --erase vim
# rpm -v --erase vim
# SuSEconfig
# exit
$ ed ~/.bashrc
export MANPATH

$ source ~/.bashrc
$ man vim
Reformatting vim(1), please wait...
Then I made vim available to root:
$ su -
# vim
-bash: vim: command not found
# ed .bashrc

alias vim='/home/tobi/bulk/run/vim/6_3/bin/vim'

# vim
-bash: vim: command not found
# source .bashrc
# vim
# exit


There are many different ways to install software on Linux. For some tools I describe how I installed them, but those are just examples; you'll most likely have different preferences and a different environment. I guess one typical strategy would be:
  1. Ask your package manager, try it on the command line: Is the tool already installed? Is it up to date?

  2. Otherwise check if there's a sufficiently recent package (eg .deb or .rpm) supplied by your distro project or vendor...

  3. ... or by the project itself ...

  4. ... or by a third party, if you trust it. In this and the former case it makes sense to check if there's a package specifically for your distro and -version.

  5. Otherwise you could get the source from the project web site then compile and install via some variation of the common ./configure;make;make install command sequence . If you don't want to risk conflicts caused by systemwide installation you can install the tool as user somewhere under your home directory, by omitting make install or by overriding the default installation directory.

  6. Or the project might provide a binary for your platform.



This howto deals with XML editing thus does not deal with setting up a DocBook publishing environment. DBX documents and schemas are used as examples representing XML languages in general. Explaining how to get (X)HTML or PDF from DBX is outside the scope of this howto. Getting started is simple, but typically there's a lot more to it.


The online version is generated by a set of XSLTs I have written (they are not a customization layer for an existing package).


If you're looking for XSLTs that you can use to transform any DocBook document to various formats, you might want to check out the XSLTs. They are very complete and have various customization hooks. The project provides support.