Most of the examples and instructions will only work as shown
when carried out in an environment
set up as described in the previous
chapters.
But many of them might work with your settings when you adjust the
various details.
They are meant as illustrations of the respective general idea
and not as perfect recipes.

Turn on XML mode via [mapleader] x,
then enter insert mode via i.

To create a pair of tags enter the opening tag, you should get the
closing one for free. Now you can enter content, for example text.

<foo>bar</foo>

If you want the content to be indented start again but this time hit
> again after having closed the opening tag
:

To learn more about folding see
:help folding
and
:help fold-commands.

With xmledit

Turn on XML editing mode via
[mapleader] x.

To mark up
the literal command name string in

<para>
Use cd to go to a different directory.
</para>

select it (eg via
2 G w v e),
then type
[mapleader] x
in quick succession (eg
\ x
or
, x).
At the prompt, enter the name of the element, eg
command, then press enter twice.
You should get something like the following:

<para>
Use <command>cd</command> to go to a different directory.
</para>

With Recording

Although the above method is convenient it is not the best
choice when there are more than one text portions to be marked up
because it can't be repeated or automated easily. But Vim lets you record
actions, the documentation describes this under "complex
repeats", see :help recording.

Let's say you want to mark up the acronyms in

<para>These XSLTs can be used for transforming
DBX to XHTML.</para>

Search for groups of uppercase characters via
/ \ u \ { 2 , } [enter]
Enter n until you reach the first acronym you want to
mark up. Then record one of the following macros:

Now the cursor should be at the beginning of the next group of
uppercase characters. If you want to mark it up (if it's an acronym
that's not yet marked up) do
@ a, otherwise
do n to jump to the next group of uppercase letters.
To repeat the last executed recorded action do
@ @.
You should get this:

<para>These <acronym>XSLT</acronym>s can be used for transforming
<acronym>DBX</acronym> to <acronym>XHTML</acronym>.</para>

Recording

Let's say you have some space-separated strings which you want
to mark up as XHTML table:

Substitution

Using substitution commands should be faster than using
recorded macros in XML mode. Hundreds of lines should be marked up
instantly, thousands of lines still take less than a second on my box.
With thousands of lines, undo can take seconds though; test and adjust
your command line with a small number of representative
lines before you run it on larger data sets.

The following examples show how semicolon-separated data
which has been exported from a spreadsheet application can be marked
up as XHTML table.

If the data is simple you can use simple commands.
Here's some CSV data which has

Transforming CVS data to
XHTML would typically not be done by manipulating a
text editor buffer with commands but by running a little script on a
file, but let's try another example just for the fun of
it.

Spreadsheet

Here's some more complex CSV data, as exported from
a spreadsheet app:

1;2;3;4
"this field contains a line
break and a record ; separator";4;6;"line
break"
;8;12;
"quoted ""word""";16;;
;;"record ; separator";

Inserting a record separator at the end of each record which is at the
end of the line simplifies things a bit:

:v/"[^";]\+$/ s/$/;/

To mark up all records in the buffer as table cells do

:%s/\("\(""\_.*""\|\_[^"]*\)"\|[^;]*\);/<td>\1<\/td>/g

Mark up table rows:

:%s/\(^\(<td>\_.\{-}<\/td>\)\{-}\)\(\n\|$\)/<tr>\1<\/tr>\3/g

All this is still based on some assumptions; before you process real
data run tests with some lines representing your data and adjust the
commands.
Cleaning up is not simple either, here's a cheap way to remove the
double quotes inside quotes

<tr><td>1</td><td>2</td><td>3</td><td>4</td></tr><tr><td>this field contains a line
break and a record ; separator</td><td>4</td><td>6</td><td>line
break</td></tr><tr><td></td><td>8</td><td>12</td><td></td></tr><tr><td>quoted "word"</td><td>16</td><td></td><td></td></tr><tr><td></td><td></td><td>record ; separator</td><td></td></tr>

Now you could insert dashes into the empty cells

:%s/\(<td>\)\(<\/td>\)/\1-\2/g

mark up the line breaks

:v/<\/tr>$/ s/$/<br \/>/

and then wrap the whole thing in an XHTML table.

Table in Browser

Important

From Vim's command line, you can call any tool
which is available on your system's path.
So when there's a repetitive task like writing lots of similar tags,
you could ask your favorite programming language to do it for you.

then place your cursor where the content should go, eg via
G 2 k.
Enter the following in Vim's command line,
all in one line.
You can paste it (after having pressed :),
eg via the middle mouse button
(don't forget to delete the duplicate :).

This only automates part of the task and is not really general
but unlike XSLT
it leaves CDATA sections intact (simply skip them)
which make editing of code listings easier.
If you get it to work for titles spanning multiple lines send me an
email :).

Sometimes a task is expressed best using XPath.
Simpler stuff can be done conveniently from Vim's command line,
without having to create an XSLT file.

Rows

Here's an example showing a simple two-step approach to the common
task of marking table rows
with alternating attributes.
This way the command lines become shorter and easier to write.
Between each screen the command line is listed which describes the
change between the previous and the following screen.

XMLStarlet also supports long options
(eg --insert
as alternative for -i), but the short versions save
typing and space, which is especially useful when calling XMLStarlet
from the shell and not from a script.