Common insertion commands of vim

Time:2021-7-22

Start inserting after the cursor\
A # start inserting at the end of the line where the cursor is\
I # start inserting in front of the cursor\
I # start inserting before the line where the cursor is\
O # insert another line under the cursor line\
O # insert another line on the cursor line

soaandicontrary,AandIcontrary,oandOcontrary.

Cursor positioning command

H # the cursor moves to the left

The cursor moves up

K # the cursor moves down

The cursor moves to the right

Move the $# cursor to the end of the line

0 # the cursor moves to the beginning of the line

H # the cursor moves to the top of the screen

Move the cursor to the middle of the screen

The cursor moves to the bottom of the screen

Set Nu set line number

Set nonu cancel line number

N enter the line number N and position the cursor on the line

Ng input line number n

G the cursor moves to the last line

GG move the cursor to the first line

Delete command

X delete the character where the cursor is

Nx delete n characters after cursor start

DD delete the cursor line

NDD delete the N lines after the cursor line

DG delete cursor starts at the end of the file

D delete the cursor from the beginning to the end of the line

N1, n2d delete the lines between N1 and N2

Copy and paste

YY or Y copies the line of the cursor

DD cuts the cursor line

NDD cuts n lines under the cursor line

P paste under the cursor line

P paste on the line where the cursor is

Replacement and cancellation

R replaces the character of the cursor

R replaces the character after the cursor until you press ESC to cancel

U cancel the previous operation

Search and replace

/Keywords are case insensitive: set IC case sensitive: set noic n finds keywords down and N finds keywords up

%S / replaced / replaced / g full text replace keyword

N1, N2S / replaced / replaced / g keyword replacement from line N1 to line N2

The final / g will not let you confirm whether to replace, if it is / C will let you confirm one by one.

Save exit ZZ =: WQ followed by! Ignore write permissions

: w / dir / filenamesave the file you are editing as a file name

R file1 imports the contents of file1 file into the currently edited file

! Command can execute other commands without quitting VI

r ! Command can directly import the result of command execution into a file, for example: R! ls /root/file1

Map definition shortcut

AB A is automatically replaced by B

The VIM configuration file is. Vimrc in the user directory. You can edit it to make some default settings.


vim

This work adoptsCC agreementReprint must indicate the author and the link of this article

I don’t know anything, but I like pretending to know nothing