当前位置:网站首页>Common operations in VIM

Common operations in VIM

2022-06-25 14:56:00 Long water and sky

One 、 Three working modes

1. Command mode
In this mode , Use the arrow keys and k、j、h、i Move cursor position , In addition, the contents of the file can be copied 、 Paste 、 Replace and delete .
2. The input mode
In this mode ,Vim You can write to a file , Enter... In command mode i、I、a、A、o、O Wait to insert the command , After editing, click Esc Key to return to command mode .
3. Edit mode
This mode is used to save the specified contents in the file 、 Find or replace . Type... In command mode “:” key , here Vim At the bottom left of the window “:” Symbol , You can input relevant instructions for operation .
After executing the command Vim Will automatically return to command mode , To return directly to the command mode , Knock Esc that will do .

Two 、 Shortcut direction keys

Shortcut key Function description
h Move the cursor one bit to the left
l The cursor moves one digit to the right
j Move the cursor down one line
k Move the cursor up one line
w or W Move the cursor to the beginning of the next word
b or B Move the cursor to the beginning of the previous word
e or E Move the cursor to the end of the next word
nw or nWn Is the number , Indicates that the cursor moves to the right n Word
nb or nBn Is the number , Indicates that the cursor moves to the left n Word

3、 ... and 、 Find the text

Shortcut key Function description
/abc Find the string forward from the cursor position abc
?abc Find the string backwards from the cursor position abc
/^abc Looking to abc For the line at the beginning of the line
/abc$ Looking to abc Is the line at the end of the line
n Repeat the last lookup instruction in the same direction
N Repeat the last lookup instruction in the opposite direction

Four 、 replace text

Shortcut key Function description
r Replace the character where the cursor is located
R Replace characters from where the cursor is , Its input content will cover the text of the same length behind , Knock “ Esc” It's over
:s/a1/a2/g All of the a1 Use both a2 Replace
:n1,n2s/a1/a2/g Put... In the file n1 To n2 Everything in the line a1 Use both a2 Replace
:g/a1/a1/g Put all the a1 Use both a2 Replace

5、 ... and 、 Delete text

Shortcut key Function description
x Deletes the character where the cursor is located
dd Deletes the line where the cursor is located
ndd Delete current row ( Including this trip ) after n Line text
dG Delete everything from the cursor line to the end of the file
D Delete the cursor position to the end of the line
:a1,a2d Remove from a1 Row to a2 The text content of the line

6、 ... and 、 Copy and paste text

Shortcut key Function description
p Paste the contents of the clipboard behind the cursor
P( Capitalization ) Paste the contents of the clipboard in front of the cursor
y Copy the selected text to the clipboard
yy Copy the cursor line to the clipboard , This command can be preceded by the number of words n, Multiple lines can be copied
yw Copy the word at the cursor position to the clipboard

7、 ... and 、 Save exit text

Shortcut key Function description
:wq Save and exit
:wq! Save and force exit
:q Do not save , sign out
:q ! Do not save , And forced out
:w preservation , But don't quit
:w! Force save text
:w filename Save as filename file
zz immediate withdrawal

8、 ... and 、 Cursor movement

Shortcut key Function description
0 or ^ Move the cursor to the beginning of the current line
$ Move the cursor to the end of the current line
n$ When the cursor moves to the current line, only n The end of the line ,n Is the number
gg The cursor moves to the beginning of the file
G Move the cursor to the end of the file
nG Cursor moves to the n That's ok ,n Is the number
:n Quickly define the cursor to the beginning of the specified line ( Use... In edit mode )

Nine 、 Undo and redo operations

Shortcut key Function description
u cancel your last action
ctrl + r Resume the last operation

Ten 、 Bracket lookup operation

Shortcut key Function description
% find () [] {} The other half of the brackets , And find begin…end,task…endtask etc.
原网站

版权声明
本文为[Long water and sky]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202200516214556.html