Some VIM commands! Vim is case sensitive.
VIM Picture!
Copy-Past-Delete
Copy
Copy the current line where the cusor locate in.
yy
Copy n lines from the current line.
nyy
Past
Past to the next line.
p
Past to the previous line.
P
Delete
Delete characters from the current cusor to the end of line.
D
Delete the current line where the cusor locate in.
dd
Delete n lines from the current line.
ndd
Delete from the first line to the current line where the cusor locate in.
d1G
Delete the character where the cusor locate in.
x
Delete n characters after the cusor(ps: include it).
nx
Delete the character before the cusor.
X
Delete n characters before the cusor(ps: not include it).
nX
Search-Replace-Undo
Search
Search down from the place of the Cusor.
/str
Search up from the place of the Cusor.
?str
Search the next one.
n
Search the previous one.
N
Replace
Replace all ‘abc’ to ‘123’.
:%s/abc/123/g
Replace ‘abc’ to ‘123’ one by one.
:%s/abc/123/gc
Undo
Undo the last operation.
u
Repeat the last undo operation.
ctrl + r
Restore the file to the initial state.
:e!
Insert-Save-Quit
Insert
Insert before the cusor.
i
Insert at the begin of the line where the cusor locate in.
I
Insert after the cusor.
a
Insert at the end of the line.
A
Insert at the next line.
o
Insert at the previous line.
O
Replace
Replace the character where the cusor point to.
r
Change to the ‘Replace Mode’ from the cusor’s place.
R
Exit the ‘Edit Mode’.
ESC
Save
Save the content.
:w
Forced save.
:w!
Save file as fileName.
:w fileName
Save file from the n1 line to the n2 line as fileName.
:n1,n2 w fileName
Quit
Quit the file.
:q
Forced quit.
!q
Forced save and quit.
wq!
Save and Quit
:x
Cusor Movement
Left-Down-Up-Right
h j k l
The cusor move to the beginning of the line.
0
The cusor move to the end of the line.
$
The cusor move to the end line of the file.
G
The cusor move to the first line of the file.
gg
The cusor move to the n line.
nG
or
:n<Enter>
Move down n lines.
n<Enter>
Move back n characters.
n<Space>
Page up.
ctrl + b
or
pageup
Page down.
ctrl + f
or
pagedown
Block Operation and Multiple file editor
Block Operation
Select character
v
Select line.
V
Select Block
ctrl + v
Copy the selected data.
y
Delete the selected data.
d
Multiple file editor
Edit two files at the same time.
vim file1 file2
List the file list.
:files
Edit the next one.
:n
Edit the previous one.
:N
Multiple window operation and Other operations
Multiple window operation
Open another file when one file was opened.
:sp file2
Switch window down.
Press 'ctrl + w', then press 'j'
Switch window up.
Press 'ctrl + w', them press 'k'
Other operations
Show the line number.
:set nu
Do not show the line number.
:set nonu
Insert the content of the file of ‘filename’ to the place of the cusor.
:r filename
Leaving vim for a while and execute the command ‘command’.
:!command