WordPress has a wonderful source code highlighting feature via the sourcecode tag. However, publishing source code online can be a pain and ends up looking up ugly and messed up without resorting to using some sort of syntax highlighter.
Vim is my weapon text editor of choice. I don’t claim it is the ultimate text editor but it fulfills my current needs for writing code. Vim’s syntax highlighting is a standard yet appreciable feature. So after some googling around I came across a solution posted by Maciej BliziĆski which saves the syntax highlighted source code you would view inside vim as good old HTML. The magical vim command is:
Below is a screenshot showing the output of the above vim command which generates the HTML for the source in a split window view:
The html generated above viewed in Konqueror:


The standard way to do this is to type :TOhtml. If you first enter :let html_use_css = 1, and then highlight some code, and then issue :TOhtml, you will get HTML that doesn’t use font tags, but instead uses CSS to provide your syntax highlighting.
Font tags be damned.
:h TOhtml to learn more.
Now if only VIM’s syntax highlighting wasn’t so buggy…
[...] 3, 2008 in hack, tips, vim Thanks to mileszs for posting a comment on the last blog post and informing me of a better way of generating vim’s syntax highlighted [...]
Great post!
If you’re doing this more than once, probably easiest to just had these things into the _VIMRC or .VIMRC VIM/GVIM configuration file.
For example, I added the following to the bottom of my file.
“Export to XHTML Customizations
:let html_number_lines = 0
:let use_xhtml = 1
:let html_use_css = 1
If you have access to a MS Windows machine, Tomas Restrepo has a Windows Powershell script which will convert a color scheme to a CSS file so you can separate the content. It works pretty well and can probably be tweaked as needed.
http://winterdom.com/weblog/2008/08/01/StylingCodeForBlogVim2Css.aspx