1. Introduction
Vim/vi is a powerful full-screen text editor and the most commonly used text editor for Linux/Unix. Its function is to create, edit and display files.
2. Insert command
a Append text after the cursor
A Append text at the end of the line
i inserts text before the cursor
I insert text at the beginning of this line
o Insert a new line under the cursor
O inserts a new line at the cursor
3. Positioning command
h, left move one character to the left
j, down move down a line
k, up move up a line
l, right move one character to the right
$ move to end of line
O move to the beginning of the line
H Move to the top of the screen
M Move to the center of the screen
L Move to the bottom of the screen
G to the last line
ng to the nth line
gg to the first line
Fourth, delete the command
x deletes the character at the cursor
nx delete n characters after the cursor
dd deletes the line where the cursor is located, ndd deletes n lines
dG delete the line where the cursor is located to the end of the content
D delete the cursor to the end of the line
5. Copy and paste commands
yy, Y copy the current line
nyy, nY Copy n lines below the current line
dd cuts the current line
ndd cuts n lines below the current line
p, P Paste under or on the line where the current cursor is located
6. Save and exit command
:w save changes
:w new_filename save as the specified file
:wq save changes and exit
:zz shortcut, save changes and exit
:q! Quit without saving changes
:wq! save changes and exit