1.Three command modes of VI:
1) Command (command) mode, which is used to enter commands;
2) Insert (insert) mode, which is used to insert text;
3) Visual (visual) mode, which is used for visual high-level
2. Save and exit the file
2.1):w save;
2.2):w filename save as filename;
2.3):wq! save and exit; 2.4
):wq! filename Note: save with filename as the file name
2.5):q! Exit without saving; 2.6
):x should save and exit, the function is the same as :wq!
3. Cursor move
3.1)j move down one line;
3.2)k move up one line;
3.3)h
3.4)l move one character to the right; 3.5
)ctrl+b move up one screen;
3.6)ctrl+f move down one screen;
3.7)up arrow move up;
3.8)down arrow down move;
3.9) left arrow move left;
3.10) right arrow move right;
3.11) $ move to end of line
3.12) gg move to beginning of document
3.13) GG move to end of document
3.14) ctrl + f page forward
3.15) ctrl + b page backward
4. Insert mode
4.1) i insert before the cursor;
4.2) a insert after the cursor;
4.3) i insert at the beginning of the line where the cursor is located;
4.4)A insert at the end of the line where the cursor is located;
4.5)O insert a line above the line where the cursor is located;
4.6)o insert a line below the line where the cursor is located;
4.7)s delete a character after the cursor, and then enter the insert mode;
4.8)S delete the line where the cursor is, and then enter the insert mode;
5. Delete text content
5.1)x a character;
5.2)#x delete several characters, # means a number, such as 3x;
5.3)dw delete a word ;
5.4)#dw delete several words, # is represented by numbers, such as 3dw means delete three words;
5.5)dd delete one line;
5.6)#dd delete multiple lines, # represents numbers, such as 3dd means delete cursor line and cursor
5.7)d$ Delete the content from the cursor to the end of the line; 5.8
)J Clear the space between the line where the cursor is located and the previous line, and connect the cursor line and the previous line together;
6.Restore modification and recovery Delete
6.1) u undo the modification or deletion operation;
7. Visual mode
The visual mode is provided by vim, vi has no visual mode, if we want to call vim when we type vi ***.txt, we can enter the following command:
echo alias vi=vim >> /etc/profile
After the next login, Use the vi command to open the file to directly call vim
8. Copy and paste
8.1)yy copy the current line
8.2)#yy copy multiple lines, # is represented by numbers, such as 3yy to copy three lines;
8.3) If in visual mode , y can copy the selected content
8.4) p paste after the cursor
8.5) shift + p paste before the cursor
9. Find and replace
9.1)/SEARCH Note: forward search, press the n key to move the cursor to the next
9.2)?SEARCH Note: reverse search, press shift+n, move the cursor to the next qualified place 9.3
):s /SEARCH/REPLACE/g Note: put the current cursor in the line
9.4):%s /SEARCH/REPLACE Note: Replace all SEARCH in the document with REPLACE; 9.5
):#,# s /SEARCH/REPLACE/g Note : The # sign represents a number, from how many lines to how many lines, replace SEARCH with REPLACE
linux vi
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=326779886&siteId=291194637
Recommended
Ranking