Preface
Vim is a powerful editor. In addition, most of these commands can be combined. For example, the 9yy command indicates copying 9 lines of content, 9 indicates the number of lines to be copied, and 100dd indicates deleting 100 lines. When the number and command work together, it is more powerful than a simple command. Similarly, the c command indicates erasure, w indicates word, cw indicates erasure of a word, and c5w indicates deletion of five words. By combining these simple commands, you can make full use of unimaginable powerful functions.
Macro command (Macros)
Some advanced editors will contain macro functions, which are certainly not missing in vim. It is very convenient to use Macros in vim:
: Qx |
Start recording macros and store the results into Register x |
Q |
Exit record mode |
@ X |
Macro commands for playing records in register x |
After you enter qx in normal mode, all your edits to the text will be recorded. If you enter q again, the record mode will be exited, then input @ x to repeat the recorded command. The command can be followed by a number to indicate the number of times to repeat. For example, @ x20 can be repeated 20 times. This is very useful in text batch processing.
Edit multiple files at the same time
Among the many vim plug-ins, there is a plug-in called minibuffer, which is called the tab function below. You can edit multiple files at the same time.
Tag command
: Tabe fn |
Edit the file fn in a new tab |
Gt |
Switch to the next tab |
GT |
Switch to the previous Tab |
: Tabr |
Switch to the first tab |
: Tabl |
Switch to the last tab |
: Tabm [N] |
Move the current tab to the nth tab |
Yes, as you think, it is similar to eclipse, ue, and other tabs!
Window command
Ctrl + w s |
Horizontal Split Window |
Ctrl + w |
Switch window |
Ctrl + w q |
Exit the current window (because there are multiple files at the same time, this command will not affect other Windows) |
Ctrl + w v |
Vertical Split Window |
Others
Vim does not make actual changes to the file before saving, but only loads the file into the buffer. The editing of the file is actually the editing of the buffer. It will not be saved to the physical file until: w.
: E file |
Load the file to the new buffer. |
: Bn |
Jump to the next Buffer |
: Bd |
Delete a buffer (close a file) |
: Sp fn |
Split the window and load fn to the new window. |
Exit Editor
: W |
Write the buffer to a file to save the modification. |
: Wq |
Save changes and exit |
: X |
Save changes and exit |
: Q |
Exit. If the buffer is modified, a message is displayed. |
: Q! |
Force exit, discard Modification |