A VIM Convert
June 21st, 2006 | by Todd W |As you might have noted in the Now Reading pane, I’ve been working through a book on the Vi editor. The ‘why’ behind that requires a brief story.Back in mid-2005, Movable Type glitched and obliterated my blog database, flushing nearly two years with of blog activity back to my beginning in September of 2003. I tried everything I could to get it back, but it was hosed. I’m also ashamed to admit my lax attitude about backups. It was almost enough to make me quit blogging.
Time went by, and last month I migrated over to Living Dot as a host. While poking through my site files, I discovered this little orphan HTML file that contained every single post going back to the start of time. It was like a gift from on high! Here were all of those posts, even if the comments were lost forever.
Unfortunately, Wordpress can’t import raw HTML files, and I was looking at over a thousand posts that could require hand editing to get them in an acceptable XML format for import. The task looked impossible.
Until my friend Chris Gidman turned me on to Vi, or more accurately, Vi-improved, or Vim.
He ran me through a quick demo of the capabilities of this ancient Unix-based editor, and I was stunned. Text editing, for me, has always been about surfing through MS Word and making a bunch of tedious changes. Why would anyone need an editor this complex?
My HTML conversion was precisely the reason I needed this. So I picked up a book and waded in. In about twenty hours total of reading and experimenting, my HTML file is now in acceptable XML, and over half of it has already been uploaded into the Blog. You’ll see a bunch of new posts in the ALL category (at least until I get them sorted properly here in the coming days).
You may still wonder why this is a big deal. Let me give you an example.
The HTML file listed the posting date as a text string - Posted on September 11, 2004. I needed that to become 11-SEP-2004. And I needed to do that over a thousand times in a nineteen thousand line HTML file.
Then I had to perform text conversions, strip and add tags, re-order lines and so forth. How many man-hours would that be? I wouldn’t even want to guess.
It took me a few hours and a hint from Chris to arrive at this command:
:%s/Posted on \(…\).\+ \(.\+), \(.\+)/post_date>\2-\U\1\e-\3< \/post_date>
With that, every single date in the file was fixed when I hit enter.
How cool is that? Sure, it isn’t intuitive in the slightest, but I still saved a bunch of time and learned a new skill.
I’m so thrilled with VIM I’m actually looking for excuses to use it. My horizon of knowledge has grown a bit, and I feel more powerful.

3 Responses to “A VIM Convert”
By Chris Gidman on Jun 21, 2006 | Reply
You have chosen wisely.
Welcome to the big dawg league.
Oh, and you forgot to mention that Vim is FREE! It’s not for the faint of heart, but it’s free.
By Glenn Dixon on Sep 14, 2006 | Reply
Speaking of the Now Reading plugin, did you ever get it to work with the 3k2 theme?
By Todd W on Sep 14, 2006 | Reply
Hi Glenn.
It worked on 3k2, but I couldn’t get the Library page to display correctly. It would display fine on the home page in the sidebar, but if you drilled down, there were all sorts of display problems. I also had to track down some tweaks in the php file to make the page W3C compliant, but that wasn’t too difficult. The display problem was more likey a CSS issue that I never could get right (and I admit I didn’t spend a ton of time on it.)
If you look at the implementation on this theme, the errors are pretty much the same.