The maze book for programmers!

Algorithms, circle mazes, hex grids, masking, weaving, braiding, 3D and 4D grids, spheres, and more!

DRM-Free Ebook

The Buckblog

assorted ramblings by Jamis Buck

Blogging with Vim

17 September 2004 — 2-minute read

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:

  1. 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).
  1. 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…


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

I just stumbled on your blog while googling "ruby's interface to vim" (I'm pretty sure that's how most people stumble on blogs =P). I'm a bigggg fan of Vim too and I wanted to write some scripts for it, but not in Vim-script, in Ruby! If you get a chance, could you link me the Ruby/Vim interface or tutorial site, if there are any? Thanks in advance if you get this comment! I'd appreciate it verryyy much, as googling around for the past half hour has led me to nothing so far =/.
The best source of vim/ruby documentation I've seen is in the vim help pages. Just do ":help ruby" and read away. Hope that helps!