Vim as XML Editor: About
... this howto.
Access Keys
-
n
-
next page
-
p
-
previous page
-
i
-
index page
[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.
-
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
optionally delete the first line via:read $VIMRUNTIME/tutor/tutor
, then write it to some fileg
g
d
d
: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
.
Notation
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:
:'<,'>s/<span\_s\+class="bold">\(\_.\{-}\)<\/span>/<em>\1<\/em>/g
In key sequences like this one
each group of non-space characters stands for one key press.
If a space is to be entered it is listed as [mapleader]
x
i
<
c
h
a
p
t
e
r
>
>
[up]
[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>.
$ 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.Terminology
Vim
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.
$ wget -q \
> ftp://ftp.de.vim.org/unix/vim-6.3.tar.bz2
$ 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
a
#!/usr/bin/env sh
${HOME}/bulk/run/vim/6_3/bin/vim "$@"
.
w /home/tobi/data/commands/vim
56
q
$ ed
a
#!/usr/bin/env sh
${HOME}/bulk/run/vim/6_3/bin/gvim "$@"
.
w /home/tobi/data/commands/gvim
57
q
$ 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
256
/EDITOR/
export EDITOR='/usr/bin/vim'
s/'.\+$/'\/home\/tobi\/data\/commands\/vim'/p
export EDITOR='/home/tobi/data/commands/vim'
wq
272
$ rpm -v --test --erase gvim
$ rpm -v --test --erase kvim
$ su root
Password:
# rpm -v --erase gvim
# rpm -v --erase kvim
# rpm -v --test --erase vim
# rpm -v --erase vim
# SuSEconfig
# exit
$ ed ~/.bashrc
272
a
MANPATH=$HOME/bulk/run/vim/6_3/man:$MANPATH
export MANPATH
.
wq
332
$ source ~/.bashrc
$ man vim
Reformatting vim(1), please wait...
Then I made vim
available to root:
$ su -
Password:
# vim
-bash: vim: command not found
# ed .bashrc
16
a
alias vim='/home/tobi/bulk/run/vim/6_3/bin/vim'
.
wq
66
# vim
-bash: vim: command not found
# source .bashrc
# vim
# exit
logout
$
TMTOWTDI.
Tools
-
Ask your package manager, try it on the command line: Is the tool already installed? Is it up to date?
-
Otherwise check if there's a sufficiently recent package (eg .deb or .rpm) supplied by your distro project or vendor...
-
... or by the project itself ...
-
... 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.
-
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.
Or the project might provide a binary for your platform.
Note
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.
DBX to XHTML
Note
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 docbook.sf.net XSLTs. They are very complete and have various customization hooks. The project provides support.