Sunday, February 14, 2010

Quotes Headings with Vim Macros and Substitutions

Even though I had completed the Quote Index, in the pages the headings were not marked up. To do this I used both macros and substitute. Once again the substitute was much faster.

What was in the text file was:

#quote Dr Kellogg says...
#qhead Hydrotherapy Departments

The most elegantly equipped establishment for the administration
of hydriatic procedures may be only the means for bungling and
unscientific dabbling with human ailments, unless conducted under
skilled medical direction and by the aid of attendants well
trained in the versatile procedures of hydrotherapy. p 402
#end

I wanted to change it into:
<h4>Dr Kellogg says...<h4>
<h4>Hydrotherapy Departments</h4>
<p>The most elegantly equipped establishment for the administration
of hydriatic procedures may be only the means for bungling and
unscientific dabbling with human ailments, unless conducted under
skilled medical direction and by the aid of attendants well
trained in the versatile procedures of hydrotherapy. p 402</p>
#end

After searching for Quotes (with "/#quote") If there was a heading I would use "@g", if there was no heading (ie. it was the same as the card title) I used "@x"

"@g" - make a H4 heading for the quote IF there is a heading and finish </p> after

j^2dwi<h4>~@@7</h4>^[j^i<p>^[
That is:
j^ - move the cursor down one line and to the first character on the line (ie. to the hash in #qhead)
2dw - delete two words (# and head)
i<h4> - change to Insert mode and insert the text <h4>
~@@7</h4> - <End> to move to the end of the line and insert the text </h4>
^[j - <Esc> out of Insert mode, back to Normal mode and move cursor down a line (to the body of the quote)
I<p>^[ - open Insert mode before the first character on the line and start the paragraph by inserting <p>

"@x" where there is no #qhead given, (it finds the card title and inserts it)
o^[ma?#card^Mj"zy$'apI<h4>~@@7</h4><p>^[
o^[ma - open a line below the #quote line, <Esc> to get back to normal mode and set line as "mark a"
?#card^M - search backwards for #card <Enter>
j - move down a line to the page title
"zy$ - into "register z" yank (copy) everything to the end of the line (ie the whole title)
'ap - move back to mark a (under the #quote line) and "put" the copied text (the card title)
I<h4> - before the first character of the line Insert the text <h4>
~@@7</h4><p>^[ - <End>, insert the text "</h4><p>" then <Esc> back to Normal mode

And finally: (and it was much, much faster as it was a straight-forward substitution to mark up the Quote heading)
%s/#quote Dr Kellogg says.../<h4>Dr Kellogg says...<h4>/

All up, this process took an hour.

No comments:

Post a Comment