On G +, we can see the introduction from netizens and find that Vim can highlight the code into HTML documents according to the current syntax. This is a very considerate small function.
For me, this function has at least two functions. First, put the exported HTML document directly in the blog so that the reader can see the code at a Glance. Second, convert the code to HTML format before sending it to the colleague review, to solve the problem that most of the email client code cannot be automatically aligned.
Tohtml is easy to use.
To convert the entire document to HTML, run the following command in command mode:
: Tohtml
If you only need to convert a few lines of code (such as 30 to 42 lines), execute:
: 30,42 tohtml
The following is the result of Code Conversion from my previous blog:
30 ssize_t my_show(struct kobject *kobj, struct attribute *attr, char *buffer)31 {32 struct my_kobj *obj = container_of(kobj, struct my_kobj, kobj);33 ssize_t count = 0;34 35 if (strcmp(attr->name, "name") == 0) {36 count = sprintf(buffer, "%s\n", kobject_name(kobj));37 } else if (strcmp(attr->name, "val") == 0) {38 count = sprintf(buffer, "%d\n", obj->val);39 }40 41 return count;42 }