From: http://coolshell.cn/articles/5426.html
Basic commands:
i
→InsertMode, pressESC
BackNormalMode.
x
→ Delete a character of the current cursor.
:wq
→ Save disk + exit (:w
Storage,:q
Exit) (Chen Hao note: the file name can be followed after W)
dd
→ Delete the current row and save the row to the clipboard.
p
→ Paste clipboard
Simple move cursor
0
→ Zero number, to the row Header
^
→ The first line of the line is not the position of the blank character (the so-called blank character is space, tab, line feed, carriage return, etc)
$
→ To the end of the row
g_
→ The last line is not the position of the blank character.
/pattern
→ Searchpattern
(Chen Hao Note: if multiple matches are found, press n to the next one)
Copy/paste(Chen Hao Note: Both P and P can be used. P indicates that after the current position, P indicates that before the current position)
P
→ Paste
yy
→ Copy the current row
Undo/Redo
Open/Save/exit/change the file(Buffer)
:e <path/to/file>
→ Open a file
:w
→ Inventory
:saveas <path/to/file>
→ Save<path/to/file>
:x
,ZZ
Or:wq
→ Save and exit (:x
Save only when needed. ZZ does not need to enter a colon and press Enter)
:q!
→ Exit and do not save:qa!
Forcibly exit all the files being edited, even if other files are changed.
:bn
And:bp
→ You can open many files at the same time and use these two commands to switch to the next or previous file. (Chen Hao Note: I like to use: N to the next file)
Let's take a look at how Vim repeats itself:
.
→ (Decimal point) The last command can be repeated
- N <command> → repeat a command n times
To make your cursor move more efficiently, you must understand the following commands,Never skip.
- N
G
→ To line N (Chen Hao Note: note that G in the command is capitalized, And I generally use: n to line N, for example, lines 137 to 137th)
gg
→ To the first line. (Chen Hao Note: equivalent to 1g, or: 1)
G
→ To the last line.
- Move by word:
w
→ Start with the next word.
e
→ To the end of the next word.
The strongest cursor movement:
%
: The matching brackets are moved, including(
,{
,[
. (Chen Hao Note: you need to move the cursor first to brackets)
*
And#
: Match the current word of the cursor, move the cursor to the next (or the previous) match the word (* is the next, # Is the previous)
You must remember the movement of the cursor, because many commands can be linked with the commands that move the cursor. Many commands can be used as follows:
<start position><command><end position>
For example0y$
Command means:
0
→ First come to the line Header
y
→ Copy from here
$
→ Copy to the last character of the row
D