[Linux:vim]vim automatically generates HTML code

Source: Internet
Author: User

If you copy and paste the vim-edited text directly into some blog editors, the code will be rigid in black and white. It would be nice if you could add the keyword highlighting so that the code would be easy to read. Some blog editors provide this functionality, some not, some supported languages are not comprehensive enough. Fortunately, Vim's syntax supports a large number of languages, and most popular languages can be found directly in support. If you can convert the vim display code directly into HTML is much better, so many HTML editing support blog can directly use formatted code.
There are two ways to convert code to HTML using VIM, tohtml and Syntax/2html.vim.

Syntax/2html.vim
You can convert using the following command:
: runtime! Syntax/2html.vim

Note: Official documents say the conversion is relatively slow, and it takes a long time to get a large amount of data.

TOhtml
You can convert using the following command:
: TOhtml

This command has several options to set:

If you want the line number of the code to start at 0 instead of the default of 1, you can use:
Let Html_number_lines=0
If you want to cancel and revert to the default state, you can use:
Unlet Html_number_lines

If you want to use CSS control styles in HTML to reduce the volume of generated HTML files, you can use:
Let Html_use_css=1

When reading longer code, we often prefer to enable code folding with the following command:
Set Fdm=syntax
If you generate HTML in this case, some of the code may be ignored because of folding, adding the following settings, you can ignore the code folding settings when generating HTML, and generate HTML without code folding:
Let Html_ignore_folding=1

These options must be set before the tohtml command is executed, or they can be written to ~/.VIMRC and automatically loaded each time the vim starts.




Figure 1 using the ~/.VIMRC generated by the method above
Figure 2 Vim keyboard key function diagramNote: This diagram is useful for setting up a desktop.

Reference documents:
Http://vimdoc.sourceforge.net/htmldoc/syntax.html Search 2html and tohtml
http://vimdoc.sourceforge.net/htmldoc/fold.html Introduction to Vim Fold (code folding)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.