Common commands for vi or vim editor

Insert restore operation
i currently insert
I insert a at the beginning of the line insert
a after the current insert
A at the end of the line insert
u restore an
o insert the line
under the current O insert the line on the current

esc exit the editing mode

line operation
^ go to the beginning of the line / home
$ go to the line end/end
dd delete line ndd delete n line
yy copy line nyy copy n line
p paste line
P paste above

dw delete a word
yw copy a word

D+$ delete to end of line Y+$ copy to end of line
D+^ delete to beginning of line Y+^ copy to the beginning of the line

v mode
1, ctrl+v please enter the column editing mode
2, move the cursor down or up
3, mark the beginning of the line that needs to be commented
4, then press uppercase I
5, insert a comment with , such as "#"
6. Press Esc again, and all comments will be made.
Delete multi-line comments
1. ctrl+v to enter column editing mode
2. Move the cursor up and down
3. Select the comment part and press d to delete the comment symbol.

vim command line mode
: q quit
: q! force quit
:wq Save and exit
:wq! Force save and exit When

changing a character,
press r in command mode and then modify the character to be modified. Press zz to save and exit

: set nu Display line number
: %s/root/zzzzzz/g Replace all root with zzzzzz %s
:1,5s/root/zzz/g Replace root in lines 1-5 with zzz

/ Forward lookup:/ Reverse lookup n look down N look up
: noh Uncheck highlight

Locate line
gg Locate
G at the beginning of the line locate the end of the line

vim -O /etc/passwd /etc/hosts
ctrl + ww switch multiple

files customize vim
vim ~/.vimrc
add
: set nu
save and exit
When you open a file with vim, there is a line number.



Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327055988&siteId=291194637