Sunday, February 14, 2010

Vim Find and Substitute to Finish the Links

This took longer than expected. The macros made short work of any Hyperhelper link that was spelt correctly but if I had not capitalised correctly or left out the underscore or just plain mispelled it, then the macro didn't work.

Another problem is that PCWrite didn't put the usual line endings in the code and even though Vim knew it was a DOS file, it maintained the same line wrapping as PCWrite which meant that some links wrapped over what Vim thought was a line break.

So there were many "missing links". In order to get the last 10%, I used the "Sections" in Hyperhelper. A Hyperhelper stack could have sections beginning with the line "#section" and ending with #ends

The first card of the section was, by default, an index card for that section.

By searching through each file (/#section) I was able to jump from section to section, checking that all the links were correctly marked up. As the cards were nearby in the same file, it was fairly simple to run the macros for fixing these links.

The last and more labour-intensive method of finding broken links was to write down each one I found as I moved around the files. I would have done about 200 this way.

I used the substitute command on each errant link I found. Some had a dozen, or so, occurrences, some only one. The substitute command looked like:

You saw this in the last post but it means:
%s - through the whole file, substitute for...
/^Ro/ - literally <Ctrl>-R o meaning the contents of "register o" ("o"riginal name - put in the register with a "oy2W or "oyf(end letter)).
/=@l/ the contents of "register l" ("l"ink name) - (put in the register with a "ly2f> on the link on the target file's #card line - this is the substitute text
^M - <Enter>

To fill the register in both cases I used "f". The syntax is [count]f {character}, which means Search forward to the the character on the current line and stop on the the character. "t" does a similar thing but the cursor stops before the character specified.
In the case above "ly2f> means that register l ("l) would consist of text yanked from the cursor to the second occurrence of ">" on the line. In other words register l would end up containing:

<a href="VisceralCongestion.html">Visceral Congestion</a>

That would take ages to type but was very quick using this method. In any case it took about two months to finish all the links.

No comments:

Post a Comment