Copy/Paste Highlighted Code with Vim

March 27, 2012

So, I’m preparing a presentation to give at work for one of our “brown bag” / “learning lunch” sessions and I want to put in some code into my slides…

When I used to use TextMate, I used the very cool copy as RTF bundle, for such tasks.

But now I’m a Vim head, here’s how to do the same in Vim…

First, install the highlight library (brew install highlight on the mac), then install the rtf-highlight Vim plugin* - I recommend vundle to manage your plugins.

Now all you have to do is run the command :RTFHighlight <language> and the contents of your current buffer (or text selection) will be added to your clipboard as glorious syntax highlighted rich text, ready to paste into keynote etc! :)

* You may need to apply the changes from this pull request to the Vim plugin to get it to work with more recent versions of the highlight library.