History
Article Edit this page Discussion

Convert selected text to HTML

From Vim Tips Wiki

Jump to: navigation, search

Tip 930 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.

[edit] 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.


Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Doctor Who
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Mystery Science Theater 3000
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Convert selected text to HTML"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation