Hello, hello, I am the next artist! A novice who is learning Linux system! It is said that proficient use of the Vi editor is a basic operation for an old programmer. So next, I will bring you the instructions and functions of commonly used Vi editors. Vi editor is a very important tool in Linux system. The vi editor is the most basic editor under the Linux system, working in character mode. Because it does not use a graphical interface, Vi's work efficiency is very high, and its functions in system and service management are unmatched by editors with graphical interfaces. The Vi editor has three modes: command mode (command mode), input mode (insert mode) and last line mode (last line mode)
command
effect
en xxx
vi a file, edit this file
vim xxx
Enhanced file editor is a development tool, you can also edit a file
! vi /! come
Go back and automatically open the last edited file
Command mode
After opening the file with the vi editor, the command mode is entered by default. In this mode, you can control the navigation through the keyboard to move, copy, paste, and delete text.
Shortcut keys for inserting content
a
Insert content after the current cursor.
A
Insert content at the end of the line where the cursor is
i
Insert content before the current cursor position
I
Insert content at the beginning of the line where the cursor is.
The
Insert a new line after the line where the cursor is
THE
Insert a new line before the line where the cursor is
mobile
command
effect
^/0/Home
Move to the beginning of the line
$/End
Move to the end of the line
G
Move to the bottom line
#G
Move to the specified line
delete
Command effect
x / Del
Delete a single character at the cursor
dd
Delete the line where the cursor is
#dd
Delete the # line starting at the cursor
d^
Delete all characters from the cursor to the beginning of the line
d$
Delete all characters from the current cursor to the end of the line
Copy and paste
command
effect
yy
Copy current line
nyy
Copy the following n lines including the line where the cursor is
ye
Copy from the cursor position until the end of the current word
and $
Copy from the cursor position to the end of the current line
and{
Copy from the beginning of the current paragraph to the cursor position
p
Paste the copied content to the cursor position
Input mode
Only in the input mode can the file content be modified. The operation in this mode is similar to that of Windows Notepad. There is no direct conversion between the input mode and the last line mode.
Last line mode
The bottom line mode can save the file, search, exit the editor and other operations.
Find
command
effect
/xxx
Find xxx
n
Look down
N
Look up
Revoke
command
effect
U
Undo all edits made to the current line
u
To undo the last operation, you can undo the most recent operation multiple times in succession, just press u continuously.
Show line number
command
effect
: set no
Show line number in editor
:set nonu
Suppress the line number in the editor
replace
:[Replacement range] s/old content/new content/g
Replace content
:% s/old content/new content/g
Full text range replacement
:n,ms/old content/new content/g
From row n to row m
:/g
All matching results in each line are replaced, if there is no /g, it means that only the first matching old content of this line is replaced
drop out
command
effect
:q
drop out
:q!
Force quit
wq
Save and exit
:x
Save and exit
ZZ
Save and exit
If you find it useful, you are welcome to bookmark, comment and forward! ! !