Skip to Content
Learning the vi and Vim Editors, 7th Edition
book

Learning the vi and Vim Editors, 7th Edition

by Arnold Robbins, Elbert Hannah, Linda Lamb
July 2008
Beginner
492 pages
16h
English
O'Reilly Media, Inc.
Content preview from Learning the vi and Vim Editors, 7th Edition

HTML Your Text

Have you ever needed to present your code or text to a group? Have you ever tried to do a code review but were using someone else’s Vim configuration and couldn’t figure it out? Consider converting your text or code to HTML and viewing it from a browser.

Vim provides three methods to create an HTML version of your text. They all create a new buffer with the same name as the original file and the suffix .html Vim splits the current session window and displays the HTML version of the file in the new window:

gvim “Convert to HTML”

This is the friendliest method, and is built into the gvim graphical editor (described in Chapter 13). Open the Syntax menu in gvim and select “Convert to HTML.”

2html.vim script

This is the underlying script invoked by the “Convert to HTML” menu option described in the previous item. Invoke it through the command:

:runtime!syntax/2html.vim

It doesn’t accept a range; it converts the whole buffer.

TOhtml command

This is more flexible than the 2html.vim script, because you can specify an exact range of lines you want to convert. For instance, to convert lines 25 through 44 of a buffer, enter:

:25,44TOhtml

One advantage of using gvim for HTML conversion is that the GUI lets it accurately detect colors and create correct corresponding HTML directives. These methods still work in a non-GUI context, but the results are less assured to be accurate and may not be very useful.

Note

It’s up to you to manage the newly created file. Vim does not save it for you; ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning the vi and Vim Editors, 8th Edition

Learning the vi and Vim Editors, 8th Edition

Arnold Robbins, Elbert Hannah
Vim Masterclass

Vim Masterclass

Jason Cannon
Mastering Vim

Mastering Vim

Ruslan Osipov

Publisher Resources

ISBN: 9780596529833Errata Page