Saturday, March 24, 2007

Syntax highlighting in colour in HTML  [Digg.com This!]

I recently found a fantastic feature in GVIM that allows me to syntax highlight my code and turns it into HTML. I'm sure there are tools out there specifically for this job, but given the convenience of having this built into my editor I couldn't help but mention it.

You can get GVIM from their website. When you've loaded your code up (and practically every language is supported), click the Syntax -> Convert to HTML menu option.

Here's a sample:


<?php

if (isset($_GET['album']))
{
//echo 'gallery: ' . $_GET['album'];
$d = dir('Photos/' . $_GET['album']);

$bFirst = true;
while ( ($file = $d->read()) !== false)
{
if (strpos($file, 'tb.jpg') !== false)
{

3 Comments:

At 7:36 AM, Cornelius said...

you can also use ":TOhtml" to convert code to html.

See:
:help convert-to-html

 
At 4:47 AM, Johan said...

Thanks alot! I knew about the feature in GVIM, but I have tried to find a way to do it in console VIM as well. Nice one, cornelius!

 
At 3:20 PM, Olivier said...

I've written a long post about how I use Vim to highligth source code samples on my blog: Syntax highlighting on this blog using semantic tags and Vim.

 

Post a Comment

<< Home