Aug-14, 2021 · 10min
change languageLearn Vim editor, including various mode switching, text editing commands, movement operations, search and replace, etc.
VIM has multiple modes: basic mode and derived mode
Default mode, the first time you open a file with VIM, you enter this mode. Also called command mode
Use
Ctrl + gto display the current file name and some other information
In Normal mode, enter
v,VorCtrl + vto enter visual mode. This mode can select an editing area, and then performinsert,delete,replace,change caseetc. operations on the selected file content.
Character selection mode: select all characters passed by the cursor, enter v in normal mode
Line selection mode: select all lines passed by the cursor, enter V in normal mode
Block selection mode: select all text in a rectangular box, enter Ctrl + v in normal mode
Use
oto switch between the top left and bottom right of the selected area
Use mouse or cursor key to highlight text
Any input will replace the highlighted text
Enter insert mode
You can insert your input into the current document
Enter insert mode from normal mode
i 光标的前一个字符处I 光标当前行的行首a 光标的后一个字符处A 光标当前行的行尾o 光标当前行的下一行O 光标当前行的上一行Enter command-line mode from normal mode
Some commonly used commands
:set number display line number, short for :se[t] nu[mber]:set nonumber close display line number, short for :se[t] nonu[mber]:set relativenumber display relative line number, short for se[t] rnu , this will set :se nu at the same time, the current line will display the absolute line number, and the upper and lower parts will display the relative line number:w save the current edited file:wq save the current edited file and exit:w! force to save the current file:q exit vim:q! force exit:write [fileName] save the current file as fileName and open:saveas [fileName] save the current file as fileName, short for :sav [fileName]/ search, n find the previous, N find the previousreference
https://www.bilibili.com/read/cv12686699
Ex means Execute
Use
gQin normal mode to enter, use:visualto exit
Enter insert mode from normal mode
i the previous character of the cursorI the beginning of the current linea the next character of the cursorA the end of the current lineo the next line below the cursorO the previous line above the cursorIn normal mode
x delete the one character at the cursor positiondd delete the line where the cursor is locatedd0 delete the beginning of the current lined$ delete the end of the current linedb 、dB delete the beginning of the current worddw 、dW delete the end of the current wordcb 、cB delete the beginning of the current word, and enter insert modecw 、cW delete the end of the current word, and enter insert modeIn normal mode
yw copy the content from the cursor position to the end of the current word
yy copy the current line
p copy the copied text content to the next character of the cursor
P copy the copied text content to the previous character of the cursor
r replace the one character at the cursor positionR replace until the ESC key is pressedu undoU undo the content:w save the current edited file:wq save the current edited file and exit:w! force to save the current file:write [fileName] save the current file as fileName and open:saveas [fileName] save the current file as fileName, short for :sav [fileName]In normal mode, you can use h 、j 、k 、l to move left , down , up , right
gg to the beginning of the current line
G to the end of the current line