Blogging with Vim
Vim has long been my favorite text editor. They’re trying to get us to use an IDE at work for our Java development (Eclipse), but nothing seems to beat Vim (for me at least) when it comes to power and ease of use. (Note: I said nothing about ease of learning… Vim definately has a steep learning curve.)
So, once I’d decided to return to the blogging scene, I had a few requirements:
- The articles had to be editable in-place, meaning that no matter where I was, or what computer I was using, I could use a web interface to compose new articles (or edit existing articles—see the next bullet point).
- I needed the ability to have posts in either of two states: draft, or published. In the draft state, no one could see them but me. These were the posts that were still being composed; this allowed me to leave articles have written and return to them later. The published state was for articles that were publicly visible.
Rublog, out of the box, offered neither of these features. However, since it was written in Ruby (and very well-written, I must say), I was able to hack together some utilities that accomplished the above.
So, all I needed now was to be able to compose and publish my articles directly from my favorite editor…
XML-RPC
Here’s where things got fun. I wrote a small CGI script in Ruby that acted as an XML-RPC server, accepting requests conforming to the MetaWeblog API. It handled such basic blogging tasks as posting a new article, editing an existing article, retrieving a specific article, and so forth.
Then, I wrote a Vim/Ruby script. This was my first real use of Vim’s Ruby interface, and I must say it worked very well. Using Ruby’s built-in XML-RPC libraries, I was easily able to write an XML-RPC client that integrated with Vim, parsing the current buffer for hints as to category, title, blog, and so forth, and then invoking the remote procedure to actually post the text.
In fact, this very article was composed in Vim and posted to my blog via XML-RPC!
Ruby made this all so easy! The XML-RPC CGI server script was under 200 lines of code, and the Vim/Ruby script was just over 100. The scripts themselves are pretty hacked together, but if I have some time I’ll try to clean them up and generalize them to the point where other bloggers might find some use in them. Great fun!
Reader Comments
6 Apr 2006
6 Apr 2006