Command to enter vi
vi filename: Open or create a new file and place the cursor at the first line
vi n filename: Open the file and place the cursor at the beginning of line n
vi filename: Open the file and place the cursor at the beginning of a line
vi /pattern filename: Open the file and place the cursor at the first string matching the pattern
vi -r filename: The system crash occurred when I was editing with vi last time, and the filename was restored.
vi filename....filename: Open multiple files and edit them in turn
Move the cursor type command
h: Move the cursor one character left
l: Move the cursor one character right
space: move the cursor right by one character
Backspace: Move the cursor one character left
k or Ctrl p: move the cursor up one line
j or Ctrl n: move the cursor down one line
Enter: Move the cursor down one line
w or W: Move the cursor right by one character to the beginning of the word
b or B: Move the cursor one word left to the beginning of the word
e or E: Move the cursor right by one word to the end of the word
) : Move the cursor to the end of the sentence
(: Move the cursor to the beginning of the sentence
}: Move the cursor to the beginning of the paragraph
{: Move the cursor to the end of the paragraph
nG: The cursor moves to the beginning of line n
n: move the cursor down n lines
n-: move the cursor up n lines
n$: The cursor moves to the end of line n
H: Move the cursor to the top of the screen
M: Move the cursor to the middle line of the screen
L: Move the cursor to the screen line
0: (Note that the number is zero) The cursor moves to the beginning of the current line
$: Move the cursor to the end of the current line
Screen rolling command
Ctrl u: Flip half of the screen to the first file
Ctrl d: Flip half of the screen to the end of the file
Ctrl f: Turn a screen to the end of the file
Ctrl+b; flip the first screen to the file
nz: Roll the nth line to the top of the screen, and roll the current line to the top of the screen without specifying n.
Insert text class command
i: In front of the cursor
I: At the beginning of the current line
a: After the cursor
A: At the end of the current line
o: Open a new line below the current line
O: Open a new line above the current line
r: Replace the current character
R: Replace the current character and the subsequent characters until the ESC key is pressed
s: Starting from the current cursor position, replace the specified number of characters with the entered text
Save command
Press the ESC key to jump to command mode, and then:
:w Save the file but do not exit vi
:w file Save the modification to the file and do not exit vi
:w! Forced save, no vi is released
:wq Save the file and exit vi
:wq! Force save the file and exit vi
q: Do not save the file, exit vi
:q! If the file is not saved, force exit vi
:e! Give up all modifications and start editing from the last time you save the file
After that, press Enter, OK!
vi filename: Open or create a new file and place the cursor at the first line
vi n filename: Open the file and place the cursor at the beginning of line n
vi filename: Open the file and place the cursor at the beginning of a line
vi /pattern filename: Open the file and place the cursor at the first string matching the pattern
vi -r filename: The system crash occurred when I was editing with vi last time, and the filename was restored.
vi filename....filename: Open multiple files and edit them in turn
Move the cursor type command
h: Move the cursor one character left
l: Move the cursor one character right
space: move the cursor right by one character
Backspace: Move the cursor one character left
k or Ctrl p: move the cursor up one line
j or Ctrl n: move the cursor down one line
Enter: Move the cursor down one line
w or W: Move the cursor right by one character to the beginning of the word
b or B: Move the cursor one word left to the beginning of the word
e or E: Move the cursor right by one word to the end of the word
) : Move the cursor to the end of the sentence
(: Move the cursor to the beginning of the sentence
}: Move the cursor to the beginning of the paragraph
{: Move the cursor to the end of the paragraph
nG: The cursor moves to the beginning of line n
n: move the cursor down n lines
n-: move the cursor up n lines
n$: The cursor moves to the end of line n
H: Move the cursor to the top of the screen
M: Move the cursor to the middle line of the screen
L: Move the cursor to the screen line
0: (Note that the number is zero) The cursor moves to the beginning of the current line
$: Move the cursor to the end of the current line
Screen rolling command
Ctrl u: Flip half of the screen to the first file
Ctrl d: Flip half of the screen to the end of the file
Ctrl f: Turn a screen to the end of the file
Ctrl+b; flip the first screen to the file
nz: Roll the nth line to the top of the screen, and roll the current line to the top of the screen without specifying n.
Insert text class command
i: In front of the cursor
I: At the beginning of the current line
a: After the cursor
A: At the end of the current line
o: Open a new line below the current line
O: Open a new line above the current line
r: Replace the current character
R: Replace the current character and the subsequent characters until the ESC key is pressed
s: Starting from the current cursor position, replace the specified number of characters with the entered text
Save command
Press the ESC key to jump to command mode, and then:
:w Save the file but do not exit vi
:w file Save the modification to the file and do not exit vi
:w! Forced save, no vi is released
:wq Save the file and exit vi
:wq! Force save the file and exit vi
q: Do not save the file, exit vi
:q! If the file is not saved, force exit vi
:e! Give up all modifications and start editing from the last time you save the file
After that, press Enter, OK!