History Report a problem
Article Edit this page Discussion

Pasting code with syntax coloring in emails

From Vim Tips Wiki

Jump to: navigation, search
 

Tip 198Previous TipNext Tip

Created: January 15, 2002 Complexity: basic Author: Hari Krishna Dara Minimum version: 5.7 Karma: 55/26 Imported from: Tip#198


When sending code snippets or diffs to your colleagues either for code review or for something else as email, how nice and clear it will be if you can paste it with the Vim syntax highlighting? I am sure they will be impressed and feel much easier to read the code. It is also very easy and fast (once you practice it) to do this.

This probably works only on windows and requires you to use Internet Explorer and an email client that understand RTF content coming from clipboard, such as Outlook or Outlook Express. At least that would make the process faster. I haven't tried on any other combination though. This is what you need to do:

  • Open the file containing the code/code snippet/diff etc. in gvim. If you use dark background for GVim (like me), then I would suggest you to change your color scheme temporarily to something else that has a white background or just use the "-U NONE" as below:
gvim -U NONE <file>
  • Convert the file into HTML by using the following command at the colon prompt as below:
:runtime syntax/2html.vim
  • The above step will open a new window with the HTML content in it. You might want to just save it with the suggested name or write into a temporary file as:
:w! c:/tmp/t.html
  • Open the IE browser window and open the above temp file "c:/tmp/t.html".
  • Now you select all (press ^A) and copy it (^C).
  • You are ready to paste it with syntax coloring in any application that accepts RTF content from clipboard, including Outlook or Outlook Express mail composing window.

[edit] Comments

 

If you are using gvim then you can convert to HTML from the Syntax menu, so you do not have to remember the right file to source.

I got it to work using Netscape. I converted to HTML, saved the file, opened the file in Netscape, and chose "Send Page..." from the file menu. This sends the HTML as an attachment. When I got the message, the attachment was displayed in-line; this depends on how preferences are set. It would probably also work to simply save the file and then attach it.


For novice users (or those who don't seem to remeber all those tricks) gVim 6 and 7 have a menu item under "syntax → ConvertToHtml" it will produce a filename.html with coloring. Use this html as you hearts desire!


Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Doctor Who
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Mystery Science Theater 3000
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Pasting code with syntax coloring in emails"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation