2008/04/13 14:40:32

from hell's heart I stab at thee, vi

So the previous blog entry looks pretty simple, right?

Wrong!

You see, I pasted the chat transcript directly into vi, which nanoblogger uses to edit blog entires. Nanoblogger uses direct html formatting, so the greater than/lesser than names were interpreted as tags, and thus didn't render. Lame!

HTML being a proper markup language, however, implements a kinda sorta escape code sequence, where you can use "&lt;" and "&gt;" (lesser-than and greater-than, get it?) to render < and > without your html interpreter (read: web browser) invisibly erasing them.

But the problem was, I had about twelve instances of < and > to replace. Text navigation in vi, while not impossibly difficult, is still awkward; and in any event, doing all that crap by hand was ideologically impure. Whatever was I to do?

Search and replace, of course!

Vi, being a Real Man's text editor, uses sed-style regex expressions for search and replace, and as I was about to discover, sed-style wildcards. The command string I first tried using was "%s/<bbot>/&lt;bbot&gt;/g" (%s/ to search every line, /g to replace every instance. The regex is of form /search string/thing to replace search string with/)

That command, of course, resulted in "<bbot>lt;bbot<bbot>gt;" instead of "<bbot>", since motherfucking sed uses & in the replacement string to mean what the search string matched. This lets you do all sorts of enormously clever things, but is a giant pain in the fucking ass when you're messing with HTML enity codes.

Now, normally, you would use shell style quoting to tell sed to ignore &, but vi isn't the shell! It ignores quotes! I, of course, only figured this out after running through every permutation I could think of, before just using the \ escape character.

Builds character, right?


Posted by | Permanent link | File under: Linux