Syntax highlighted code in Gmail with Vim

I used to paste code in emails by simply choosing the monospaced font in gmail’s web client (I don’t like native clients… well, except Android’s), in hope that the (usually) small width of the paragraph didn’t mess up with the code.

Whenever I had the need to paste snippets larger than, say, 4-5 LOC I always ended up using some external website like pastebin; this however resembled attaching files to the email too much, in that you can’t really talk about snippets in the email without having your addressees jump back and forth between tabs, like they would between windows in the attached-file case. In those cases I relied on commenting the code on pastebin, so my emails were actually cut in two (or three, or four,… depending on the number of snippets in the email).

My new process goes like this: I write the code in the editor (Eclipse or Geany), so I have autocompletion, autoformatting and tabs converted into spaces. Then, I copy and paste the code into a new file in Vim and save it as an HTML file using the


command as I learned reading this article. I open the file with Chromium (any browser will do, of course) and I copy and paste the code right into Gmail’s editor.
This way Gmail nicely inserts the HTML code inside the email, using the styles I chose in Vim, background color included!

You don’t like Vim’s color scheme? You’ll find a lot of color schemes in this wonderful website 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s