Saturday, February 19, 2011

Vim Usage: generate HTML format source code with syntax hightlight

In vim, this supports to have syntax highlight which makes the program attractive, at least it is not dull and easy to debug. Sometimes, you may want to publish your code online so people can view your program. One way is to put the source code to web host directly, so people can download your source code and view it in their own favourite editor. The other way is to publish your code in HTML format, thus people can view it anywhere once there is a web browser.

Vim provides more function on that, it can generate a HTML from your program with syntax highlight. You just need to type the following in command mode:
 ":TOhtml"
Then, you may need to wait a little bit time which depends on your size of the program. Once it is done, it will generate a html named program_name.html and you can save it by ":w" and publish it if you want. Cool~

But, if you want to modify the style, you will think it is a trouble. Vim by default won't output using CSS, for example, it uses font tags instead of using style. For formatting, it use pre tags instead of replacing space with   and newline with
tag. To force vim output using css and not pre, you can set it by ":let html_use_css=1" and ":let html_no_pre=1". If you want to output standard xhtml also, add ":let use_xhtml=1".

1 comment:

  1. I have no words for this great post such a awe-some information i got gathered. Thanks to Author.
    flash to html5 converter

    ReplyDelete