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.