Sunday, February 14, 2010

Vim Macros, Slow Edits

Now that the html links are finished and the indexes are complete, it is time to start getting the other html done.

I started with the headings. To show where I had taken the information from I used had four headings:
  1. from Hydrothermic Remedies...
  2. from Dr JH Kellogg's Prescriptions...
  3. from Dr JH Kellogg's Hydriatic Techniques...
  4. from Dr GK Abbott's Prescriptions...

Once again I used Vim's keyboard macros:

"@g" To turn all the "#from from Dr JH Kellogg's Prescriptions..." etc. to "<h2>from Dr JH Kellogg's Prescriptions...</h2>".

/#from^M2dwi<h2>~@@7</h2>^[n
That is:
/#from^M - search for #from <Enter>
2dw - delete 2 words (vim thinks "#" and "from" are both words - I could have done it with dW)
i<h2> - change to Insert mode and insert <h2>
~@@7</h2> - <End> of the line and insert </h2>
^[n - <Esc> back to normal mode and search for next occurrence of the search pattern (#from)

I did this in batches again with the command, 100@g. Even so, the whole process took several hours. It has been a long time since I could leave a computer chugging away and come back in 10 minutes and find it still working. I'm using a 1GHz machine so that could explain it.

It ran very slowly I will use substitute more in the future.

I suspect the reason it ran so slow was because I had the syntax highlighting on and Vim had recolour the rest of the file after each tag was inserted.

No comments:

Post a Comment