Site Feed

Monday, September 15, 2008

Convert a Text File to HTML

While considering how to make my shell scripts look better on the web, I started looking at freshmeat.net for programs that would convert source code to html.

Then I thought, vim already has syntax highlighting. I wonder if it has a way to convert to html.

Sure enough, it can be done with a single command:

:runtime! syntax/2html.vim

Convert Text File to HTML
:runtime! syntax/2html.vim : convert txt to html
:h 2html : help about 2html

:wq! : write the new file

The current file is converted, and an .html extension is added. Once the file is saved, it can be opened in a browser.

For more vi tips, check out:
http://systemnotesorg.blogspot.com/search/label/vi

And the official vim site:
http://www.vim.org/tips,

Here is a beautiful example of C source code that was quickly converted to HTML, while preserving all of vim's color coding:
http://systemnotes.org/download/matrix/matrix.c.html

No comments: