Vim Tips Wiki
Advertisement

Previous TipNext Tip

Tip: #930 - Convert selected text to HTML

Created: May 18, 2005 6:35 Complexity: basic Author: Anonymous Version: 5.7 Karma: 76/35 Imported from: Tip#930

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