There are many detailed commands in VIM. We have selected some commonly used entry-level commands, which are enough for daily code editing work. If you need to use other commands in the future, it is not too late to check again.
vim generally has three editing modes, namely insert mode, normal mode, and last line mode.
The following are mainly operations in normal mode. Operations in other modes will indicate the relevant modes
h------>Move left each time you press
j------>Down each time you press Move
k------>Move up each time
##l------>Every time Press to move right
Press < ;Esc> key to enter normal mode
Then enter the following methods to exit
:q #不保存并退出vim:q! #强制退出:wq #保存文件并退出:x #相当于:wq
In normal mode (Normal mode), you can press the x key to Delete the character at the cursor position.
Enter insert mode in normal mode, you can There are several methods:
You can press the i key to insert text at the cursor.
Press the a key to insert text behind the cursor.
Press the capital A key to insert text after the last character on the line where the cursor is.
Press the A key and click on the line where the cursor is. Add
to the end of the text. Press the a key and add
Enter dw to delete from the cursor to the end of a word.
Many commands that change text are composed of an operation The symbol is composed of an action.
The format of the delete command using the delete operator d is as follows:
dmotion
Among them:
## d -Delete operator
motion die through in >> motion - Delete operator
##A short action list:
w - From the current cursor position to the beginning of the next word, excluding its first characters.
e - From the current cursor position to the end of the word, including the last character.
$ - From the current cursor position to the end of the current line.
Enter the number n before the action, it will It repeats n times.
Enter 2w to move the cursor back 2 words.
Enter 3e to move the cursor backward to the end of the 3rd word.
Enter 0 (number zero) to move the cursor to the beginning of the line.
Enter the number n when using the operator , which can be repeated n times.
For example: operation number (number) motion
d2w You can delete 2 words.
Enter dd to delete a current line and save it to the register, which functions like a "cut" operation and can be used in conjunction with the p operation.
######
Enter u to undo the last executed command, and enter U to undo modifications to the entire line.
Use Ctrl + r to undo a previous undo command.
Enter p to "cut" the last time The content is placed after the cursor.
Move the cursor to the character position to be modified and enter r and a character to replace the character at the cursor position.
To change text until the end of a word, enter ce.
c [number] motion
The action parameter motion is the same, it can be w, e, $d.
Enter Ctrl + g to display the currently edited file The line position of the current cursor and file status information.
Enter capital G to jump directly to the last line of the file.
Enter nG to jump to the line with line number n.
Enter gg to jump to the first line of the file.
Enter / plus a string, you can Find this string in the current file. To find the next string, press the n key. To search in reverse, enter a capital N.
If you want to search in reverse, enter ? replace / .
Position the cursor at the bracket to be matched , enter % to find another bracket that matches it), ], }.
Enter: s/old/new, you can replace it once The string at old in this line is the string at new.
Enter :s/old/new/g to replace all the strings at old in the line with the strings at new.
Input:#,#s/old/new/g, where #,# represent the line numbers of the starting line and the ending line of the replacement operation.
Enter :%s/old/new/g to replace every matching string in the entire file.
Enter :%s/old/new/gc, each matching string in the entire file will be found, and each matching string will be prompted whether to replace it.
Enter:! Then enter an external command immediately Execute this external command.
For example, :!ls + Enter, this command lists the contents of your current directory.
5.2 More information about saving files
To save changes to a file, enter :w filename.
Select by pressing the v key To save part of the file, then enter:w file name to save the selected content to the target file.
To insert another file into the current file For the content, please enter:r file name.
Enter o, a new file will be opened under the cursor row and enter insert mode.
Enter a capital O to open a new line above the cursor and enter insert mode.
Enter uppercase R, you can Replace multiple characters in a row.
Use operator y to copy text and p to paste text.
Enter yy to copy the line where the cursor is.
can be used with the action parameter motion:
Enter yw to copy a word.
The above is the detailed content of Summarize some common commands of VIM. For more information, please follow other related articles on the PHP Chinese website!