Vim/VI has always been the most popular text editor on Unix/Linux systems. Since its access to Unix in 2001, VIM/VI has always been the preferred editor for me to modify system files and write simple programs, it is an essential tool for home travel. How to improve its writingSpeed, This article focuses on some usageTipsFor your reference.
Application tip 1: quick comments
1. Continuous Line comment
Use Vim/VI to edit the shell script. During debugging, You need to annotate multiple lines. Each time you switch to the insert mode, enter the annotator "#" at the beginning of the line. return to the command mode, which is very troublesome. In fact, if you want to annotate continuous lines, you can execute them in command mode in the following format:
:Start line, end line S/to replace character/Replace with new character/g
To comment out rows 1st to 20th, run the following command:
:1, 20 s/^/#/g
"^" Indicates that the row is inserted at the beginning, "#" indicates the character to be inserted, and "G" indicates that the replacement is not confirmed. If you want each row to interact with each other and ask whether to execute the replacement, you can change "G" to "C ".
If you want to edit the PHP script, it is a little effort to annotate it. For example, you need to annotate rows 1st to 20th and execute:
: 1, 20 s/^/\/g
The PHP annotator "//" must be specially processed, because the default "/" in the vim/VI replace command format is the delimiter, so you need to use the Escape Character "\". "/" must be written as "\/", so the command is shown above.
It is strongly recommended that you use the keyboard and fingers to save time and effort.
2. Non-continuous row comment
If you comment on multiple non-consecutive rows, you can define a shortcut to simplify the format:
:Map
Shortcut Key execution command
For example, if you define the shortcut key Ctrl + P to add the "#" comment to the beginning of the current line, you can execute:
:Map ^ p I // <ESC>
"^ P" is the definition shortcut key Ctrl + P. Note that you must press Ctrl + V + P at the same time to press this "^ P, you can also press "Ctrl + V" and then "Ctrl + P". "I // <ESC>" is the action to be triggered by this shortcut key, "I" is insert at the beginning of the row where the cursor is located, "//" is the character to be entered, and "<ESC>" indicates return to command mode, "<ESC>" must be typed one by one. You cannot press the "ESC" key on the keyboard. After the execution is successful, press Ctrl + P on any line to be annotated and the "//" number is automatically added to the beginning of the line.
To cancel this shortcut, enter the following command:
:Unmap ^ P
I like to write my mailbox in the end comment when writing a program or document. Every input is very troublesome. I simply define a shortcut key, as shown below:
:Map ^ m isam_helen@vip.163.com <ESC>
After writing the content, press Ctrl + m in the comment and enter your email address. (the author's email address is seriously exposed. I hope you can contact me more by reading this article, do not delete the lamp prayer editor ).
Application Tip 2: Messy skills
1,
The legendary command "AB"
The command "AB" can also solve the problem of the input mailbox, because I have defined too many shortcut keys in VIM/VI, for example, enter the email address, enter the contact number, enter the parity standard, and enter the phpchina administrator ...... I couldn't remember it anymore. One night later, the thunder and lightning struck me. I suddenly found this command-"AB". I finally found a solution to the problem! Oh
Yeah!
The information that is often used in the original input can be so simple, look --
:AB
Substitution Original information
Example:
:AB sammail sam_helen@vip.163.com
After the execution, input "sammail" in any place in the input mode, and then press any letter or enter a space, click it, Lima will become "sam_helen@vip.163.com", it is quite convenient! (Forgive me for exposing my email here again. I would like to make a statement that "gay" will not send emails to me. If this is not the case, thank you)
2,
It turns out to be a combination of two swords.
There are two tips in VIM/VI:
No.1
You can directly execute Unix/Linux commands in VIM/VI without exiting Vim/VI.
Sometimes you need to know the system information when writing some system scripts. Many users exit Vim/VI and execute commands to obtain information before editing. In fact, this is not necessary. To get the content in the/tmp directory, you only need to directly execute the command in VIM/VI Mode:
:! Ls/etc
After viewing the command results, press enter to continue editing.
Execute commands in VIM/VI in a simple format:
:! Command
No. 2
Other files can be directly imported into the current editing file.
Format:
:R
File Name
For example, to import the/etc/issue file, run the following command:
:R/etc/issue
Two very easy little tricks, just in a very depressing afternoon, I accidentally missed such a secret when I knocked on the keyboard-they can be used together!
For example, many programmers like to write the current time in the comments after writing the program. I have a good way to save time, speed, and accuracy. You only need to execute it in command mode:
:R! Date
The current time is automatically imported. The result of any command is imported to the current editing file in the format:
:R! Command
3,
Programming Query
I used to write some C language programs in Linux. Sometimes I have a poor memory and forget the syntax format. I can directly query them when using Vim/VI. For example, when a program is written to fork, the system suddenly loses memory (the memory of this stuff is lost), you can directly move the cursor to fork and press "K" (the capital K ), I will jump to the Linux programmer's manual. After reading the help of fork, I will press enter to continue writing --
4. configuration file. vimrc
The shortcut keys and AB commands mentioned above are only valid in the current editing file after being set. To make them permanently effective, you need to edit them in the user's home directory. vimrc file. If you are a root user, edit/root /. vimrc (this file does not exist by default ).
Write your frequently used setting commands, such:
:Set nu
:Map ^ m isam_helen@vip.163.com <ESC>
:AB sammail limingkillyou@163.com
......
It will take effect permanently!
From: http://hi.baidu.com/mgqw/blog/item/1f1e5739a53c9df53b87ce74.html