Sunday, March 7, 2010

HTML Markup with Vim Macros

So after the last post I had four files:

  1. Diseases.txt
  2. Effects.txt
  3. Problems.txt
  4. Techniques.txt

They had all their links marked up in html and all the bullet points converted to html list items. Now I had the daunting task of marking up the rest of the html.

To make markup easier I turned on Vim's syntax highlighting by simply changing the filenames to .html like this:

  1. Diseases.html
  2. Effects.html
  3. Problems.html
  4. Techniques.html

My present job is going through each of these files and manually marking up the html. Once again Vim macros have come to the fore. As I found previously the edits were quite slow on the bigger files, so split them into smaller ones. At present I am making good progress having completed Diseases, Effects and Problems in the last month and must be about halfway through Techniques.

So here is how I'm using the macros for general html tags:

@h - To make subheadings "H3"
I<h3>^[A</h3>^[j
I<h3>^[ - move to beginning of line, change to Insert mode, insert "<h3>" to begin the heading, then <Escape> to Normal mode
A</h3>^[j - start Insert mode after the last character on the line, Insert "</h3>" to end the heading, <Escape> to Normal mode and move the cursor down a line (to begin the next macro)

@p for a one-line paragraph
I<p>^[A</p>^[j
This is the same as "@h" above, except the paragraph markup is inserted. To ensure that paragraphs are one-line, I use "J", which appends the next line to the end of the present line with a space between.

@t - inserts treatment heading - often missing in Diseases
O<h3>Treatment:</h3>^[j
This opens a line above the cursor into Insert mode and insert the treatment heading then <Esc> back to Normal mode and move the cursor down a line.

I use other substitutions to make headings as well, like:
:%s+^Prevention:+<h3>Prevention<\/h3>+
and
:%s+Indications:+<h3>Indications:-</h3>+
And to get rid of redundancy in the links in the Diseases.html file:
:%s+../Diseases/++g

No comments:

Post a Comment