First, Introduction
Vim (vi[improved]) editor is an extended version of VI, more powerful than the VI function, is a powerful cross-platform text file editing tools, you can use it to create, modify text files and so on. Vim has three modes of operation, called edit mode , insert mode , and command mode , and when Vim is run, it is first entered in command mode.
Second, the command mode
VIM Command mode can do a lot of things, such as the cursor jumps to the specified word, line, copy, delete a line or even a lot of lines and the full text can, anyway, the function is really too powerful, the following to make a detailed:
(1) Cursor movement
① If you have the navigation keys for the top, bottom, left, and right arrows on your keyboard, you can do this by clicking the keys to move the cursor. In addition, you can use the following keys to complete the same character movement function:
H |
Move Up
|
J |
Move Down |
K |
Move left |
L |
Move right |
IiThe above 4 keys move the cursor position one line at a time or a
character. Vim also provides commands to move the cursor a little wider:
Ctrl+f |
Flip a screen to the end of a file |
Ctrl+b |
Flip a screen to the file header |
Ctrl+d |
Turn half screen at the end of the file |
Ctrl+u |
Turn half screen to file header |
③ jumps to the first line of the file, last line, and specifies a line to move the command in a wide range:
G |
Cursor jumps to end of file line |
Gg |
Cursor jumps to the first line of the file |
#G |
"#" Index word, enter a random number will be transferred to the specified number of lines |
④on the screen currently
one page, you can quickly move the cursor with the following command:
H |
The first letter of the cursor jumps to the first line of the current page |
M |
The first letter of the cursor jumps to the middle line of the current page |
L |
Cursor jumps to the first letter of the end line of the current page |
H M
L
commands can also be added in numbers. If the 2H
cursor is moved to the 2nd line of the screen, 3M means that the cursor is moved to the third row above the middle row, indicating that the 3L
cursor is moved to the 3rd line of the screen.
④ When you move the cursor to the line that you want , the cursor can be implemented with the following command:
W |
Move the cursor right to the beginning of the next word; |
E |
Move the cursor right to the end of a word; |
B |
Move the cursor left to the beginning of the previous word; |
^ |
Move the cursor to the first non-null character of the bank; |
$ |
Move the cursor right to the end of the bank; |
0 |
Number 0, move the cursor left to the beginning of the bank. |
(2) Search matches
In addition to the cursor movement in command mode, VIM provides a powerful string search function. To find where a specified word or phrase appears in a file, you can search directly with vim without having to do it manually.
The search method is: Type the character /
followed by the string to be searched, then press ENTER. The editor performs a forward search (that is, toward the end of the file) and, after locating the specified string, pauses the cursor to the beginning of the string; type n
a command to continue the search to find the next occurrence of the string. ?
instead /
, you can reverse-search (toward the beginning of the file) for example:
/root |
Forward search string root |
N |
Keep searching and find out where Root is next. |
N |
Continue searching to find out where Root was last. |
? root |
Reverse search string root |
(3) Character editing, substitution
the VIM General Delete command is d
, x
(the former deletes 行
The latter deletes 字符
), combined with other features of vim, can be used to achieve the basic deletion function. After you position the cursor at a specified position within a file, you can replace the character pointed to by the cursor with other characters, or delete one or more characters or rows or lines from the current cursor position. For example:
X |
Delete the character at the cursor |
#x |
Delete the # characters at the beginning of the cursor |
Xp |
Swap the position of the character where the cursor is located and the character after it |
~ |
Convert case |
J |
Remove line breaks after the current line |
R |
Replace the character at which the cursor is located |
R |
Switch to replace mode |
(4) Copy and paste
① content that is removed from the body (such as characters, words, or lines) is not really lost, but is cut and copied into a memory buffer. The user can paste it into the body at the specified location. The command to complete this operation is:
P |
lowercase p, paste the contents of the buffer to the back of the cursor |
P |
Capital Letter P, paste the contents of the buffer to the front of the cursor |
② sometimes need to copy a piece of text to a new location while preserving the contents of the original location. In this case, you should first copy (rather than cut) the specified content to the memory buffer. The command to complete this operation is:
Y |
Copy the entire row, and Y can also be used with w,e,b,$,^, such as the symbol, for example: yw represents a word where the cursor is copied |
Yy |
Copy rows |
#yy |
"#" means a number is a copy of a few lines |
# "TYy |
"#" means any number, "T" means t this shipping container, Linux has 36 cut mail containers, namely a-z,0-9; Copy rows can be selected to be placed on any of these 36 shipping containers; Paste "TP means paste the T register contents into a file.
|
(5) Revocation and repetition
In the process of editing a document, you can use the Undo command to eliminate the consequences of an erroneous edit command. In addition, if the user wants to repeat the previously executed edit command at the new cursor position, the duplicate command is available.
U |
Undo the result of the previous command, which can be used with a number. |
. |
Repeat the last command to modify the body |
Iii. Insert mode (insert) (edit mode)
(1) Enter insert mode
After you have correctly positioned the cursor in edit mode, you can switch to insert mode by using the following command:
I
|
Insert body to the left of the cursor |
A |
Insert body to the right of the cursor |
O |
Adds a new row to the next line in the row where the cursor is located |
I |
Insert at the end of the line where the cursor is located |
A |
Insert at the end of the line where the cursor is located |
O |
Add a new line to the previous line of the cursor |
(2) Exit insert mode
to exit the insert mode, press ESC
When you exit insert mode, you enter edit mode.
Iv. Extended command (extended commands) mode
in Vim's command mode, complex commands can be used. In command mode, press shift+: and a colon appears, and the command mode is now entered. The command mode is also called the last line mode , the user input content is displayed in the final line of the screen, press ENTER, Vim executes the command.
(1) Open, save, exit
:! File |
In the open vim, if you want to see a file can:! Back with the file. |
: r! File
|
Read the open file into vim |
: W File
|
Save the current file as |
Introduction to the basics of vim