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.vimscriptThis 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.
TOhtmlcommandThis is more flexible than the
2html.vimscript, 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; ...