Vim Tips Wiki
Advertisement

Obsolete tip

This tip has been merged into another tip.
See VimTip198 for the current tip.

Please do not edit this tip, and do not edit the discussion page.
If anything needs to be improved, please fix VimTip198.


Tip 930 Printable Monobook Previous Next

created May 18, 2005 · complexity basic · author Anonymous · version 5.7


You can convert selected text to HTML code in Vim using:

:TOhtml

This works with a complete file, or segments of code (selected in visual mode). GUI users can also use the drop-down menu.

This is really nice when you are writing webpages with code snippets in it:

  • Set the highlighting of the file to your programming language of choice.
  • Enter the code.
  • Select the code.
  • Type :TOhtml
  • Copy the HTML code from the window.

Comments

If you want to generate HTML automatically, for example whenever you publish a document on a website, then you can use my Perl module Text::VimColor to run Vim for you:

http://search.cpan.org/~geoffr/Text-VimColor/

It's also useful if you don't want a particular type of HTML, or if you want to generate some other format. You can get the syntax-colored code out as XML or a data structure and munge it in Perl if you want.


Since you broadened the topic, don't forget about http://qbnz.com/highlighter/ for source highlighting via web app.


Advertisement