Vim tips-Write Program comments

Source: Internet
Author: User
1. Import copyright information at the beginning of the file

Copyright information usually needs to appear at the beginning of each source code file. This part of content is the same and there is no need to repeat the input. Even copying and pasting is cumbersome, you can write this part of information into a separate file and then read it through commands. Assume that the copyright information file is copyright.txt.

When editing the source code file, move the cursor to the beginning and then execute

: R copyright.txt

2. to insert the current date, you often need to insert the modification date in the description of the source file. It is troublesome to manually enter the date. In fact, the following command can be completed.
: R! Date
The preceding two commands use the R command to read the content of an external file, and read the execution and output results of an external command. The date here can be any system command. 3. Repeated operations are often required to write a single line of code with one click. For example, to annotate a line of code in a shell script, you can use the following methods: (1) 0 ---- move the cursor to the beginning of the line; I ---- enter insert mode; input character # (2) I ------ move the cursor to the beginning of the line and automatically enter insert mode; input character # When a large number of such comments are required, such repeated operations can be completed through the definition macro. : Map ^ p I # <ESC>
Then, press Ctrl + P on the line to be annotated to complete the annotation. Note: The above ^ P input mode is to press Ctrl + V at the same time, ^ will appear, and then press Ctrl + P to complete the P input. The final <ESC> is the Escape key, so that the exit insertion mode returns to the General Command mode. The shortcut key is canceled by unmap ^ p.
4. For convenient signatures, you often need to write the author's name in the description section of the source file. It is troublesome to enter the name each time. You can use the AB command to complete the replacement. For example, if the author's name is "Zhang Dali", run the following command: AB name zhang Dali will be automatically replaced with "Zhang Dali" every time "name" is entered ". The command to cancel the replacement is unab name.
Related Article

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.