Press Esc
Exit edit mode and return to command mode.
1、:w
Write the edited data to the hard disk file ( commonly used)
2、:w!
If the file is read-only, force writing to the file
3、:q
Exit VI ( commonly used)
4、:q!
If you have modified the file and do not want to save it, use ! to force quit without saving the file
5、:wq
Exit after saving, if it is: wq!, it is forced to exit after saving
6. :w filename :wq b.txt #Separate with spaces
Save edit data as another file and exit ( similar to save as new document)
7 、: set no
show line number
8、:set nonu
cancel line number
9、dd
Delete the entire line where the cursor is located ( commonly used)
ndd
Delete n lines down from the line where the cursor is located (commonly used)
d1G
Delete all data from the line where the cursor is located to line 1
dG
Delete all data from the cursor line to the last line
10、yy
Copy the line where the cursor is located ( commonly used)
nyy
Copy the line where the cursor is located n lines down (commonly used)
y1G
Copy the line where the cursor is located to all the data in the first line
which
Copy all data from the line where the cursor is located to the last line
11、p
p means the copied data is pasted on the next line of the cursor, p means the copied data is pasted on the previous line of the cursor (commonly used)
Note that in command mode, copy yy first, then paste p
12. In linux , assign the cursor to the last line in the vi editor
Shift + G
13. Jump to the first line of the file in the vi editor
lowercase gg
or enter: 0
method/ step
1. Create a file, use vi to create a file command
vi+ filename
2. If you want to save the edited content, under the English input method, enter a colon: then enter wq, save and exit
3. If you want to exit vi , under the English input method, enter colon: and then enter q, give up saving and exit.
4. If you have modified the content of the file, but do not want to save it, under the English input method, enter a colon: then enter q, then enter an exclamation mark!, that is, force quit.
5. In command mode, you can use the dd command to delete lines in the file, or use the yy command to paste lines.