Linux VI Basic Operations

Source: Internet
Author: User

Under Linux, you can type the Vimtutor command with a vim tutorial that includes the actual operation.

three command modes in 1.VI
1) command (command) mode, for entering commands;
2) Insert (insert) mode for inserting text;
3) Visual (visual) mode, used to highlight and select the body of the visualization;

2. File Save and Exit
2.1): W save;
2.2): W filename saved as filename;
2.3): wq! Save exit;
2.4): wq! FileName Note: The filename is saved and then exited;
2.5): q! Do not save the exit;
2.6): X should be saved and exited, function and: wq! same

3. Cursor Movement
3.1) j Move down one line;
3.2) k move up one line;

3.3) h move one character to the left;
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) Upward arrow to move upward;
3.8) down ARROW to move down;
3.9) left Arrow moves left;
3.10) Right arrow move right;

3.11) $ move to end of line
3.12) GG move to document start
3.13) GG move to document trailer
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 is inserted after the cursor;

4.3) I insert at the beginning of the line where the cursor is located;
4.4) A is inserted at the end of the line where the cursor is located;

4.5) O Insert a row above the line where the cursor is located;
4.6) o insert a row below the line where the cursor is located;

4.7) s Deletes a character after the cursor and then enters insert mode;
4.8) S deletes the line where the cursor is located and then enters insert mode;

5. Deletion of text content
5.1) x a character;
5.2) #x Delete several characters, #表示数字, such as 3x;
5.3) DW Deletes a word;
5.4) #dw Delete a few words, #用数字表示, such as 3DW means delete three words;
5.5) dd deletes a row;
5.6) #dd Delete more than one row, #代表数字, such as 3dd means to delete the cursor line and the next two lines of the cursor;
5.7) d$ Delete the contents of the cursor to the end of the line;
5.8) J Clears the space between the line where the cursor is located and the previous line, and the line of the cursor and the previous line are joined together;

6. Restore and restore the deletion
6.1) U undo Modify or delete operation;

7. Visual Mode
Visual mode is provided by VIM, VI has no visual mode, if we want to type VI ***.txt call VIM, you can enter the following command:
echo Alias Vi=vim >>/etc/profile
The next time you log in, use the VI command to open the file and call vim directly.

8. Copying and pasting
8.1) YY Copy as Forward
8.2) #yy Copy multiple lines, #用数字表示, such as 3yy means to copy three rows;
8.3) If in visual mode, Y can copy the selected content

8.4) p Paste after the cursor
8.5) SHIFT + P is pasted before the cursor

9. Find and replace
9.1)/search Note: Forward lookup, press the N key to move the cursor to the next qualifying place;
9.2)? Search Note: Reverse lookup, press the Shift+n key to move the cursor to the next eligible

9.3): s/search/replace/g Note: Replace the search word in the row where the current cursor is in, and highlight all search;
9.4):%s/search/replace Note: Replace all the SEARCH in the document with a replace;
9.5): #,# s/search/replace/g Note: The # number indicates the number of lines to how many lines, the SEARCH is replaced with replace;

Linux VI Basic Operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.