Summary of using Vim commands

Source: Internet
Author: User

After entering VI, insert the lower-case "I" key after the cursor; insert the lower-case letter "O" key under the cursor; insert a lower-case letter "a" before the cursor.

For example, to copy 5 rows of data under 6th rows (including), put them under 18th rows (that is, the pasted content starts from 19th rows ).

 

Method 1 (suitable for copying a small number of lines of text ):
In command mode, move the cursor to line 6th and enter "5yy" to copy the data starting from line 6th (including line 6th) 5 rows (from 6th rows to 10th rows), then move the cursor to 18th rows, and click P to paste the copied content to the row.

 

Method 2 (suitable for copying a large number of lines of text ):
In command mode, enter ": 6, 10 copy 18". In this way, the data of the five rows starting from row 6th (that is, from row 6th to row 10th) is copied to row 18th, "copy" can also be written as "CO" or "cop ".

 

Appendix:
1. Set the line number for VI to display: write "set nu" to the ". vimrc" file in the user root directory ". If the file does not exist, create it and write it to the row.

2. The format of the two methods is also applicable to deleting (also known as cut, see the purpose) multiple rows of data, such

Method 1 (applicable to a small number of deletions or deletions) in command mode, enter "16dd" to delete 16 rows of data starting from the cursor;

Method 2 (applicable to massive deletion or cutting) Enter ": 6, 10 Delete" in command mode to delete data from 6th rows to 10th rows, "delete" can be abbreviated as "D" or "Del.

3. If you want to cut and paste data, first cut the corresponding data row according to the operation in the previous step, and then move the cursor to the previous line at which you want to paste the data, press the P key to paste the content to the specified position.

4. Undo the previous operation. In command mode, press the lower-case "U" key.

5. To search for a keyword "XXX", enter "/XXX" in command mode and press Enter.

6. If the source code is too long and you want to jump directly to Line X, enter ": X" in command mode and press Enter.

7. Save and exit. In command mode, press the uppercase "Z" key twice consecutively.

8. Repeat the operation on the previous command by pressing the period (.) In command mode.

Of course, in command mode, make sure that you press the "ESC" key twice in a row.

Other common Vim commands:

Gg = g format the entire file. If the format is not successful, you will lack the relevant configuration file =.
DG deletes the row to the end of the file
D. Delete the cursor to the end of the row.

Indent command: V enters the virtual state, and then uses '<', '>' to control the indent to the left to the right.

 

11: delete, copy, and paste X to delete a character X. delete a character X to forward, add X to NX, and delete n characters to backward. For example, 3x, delete the 3-character NX class NX from the back, change to forward D or DD, cut the row where the cursor is located to the clipboard, and then enter P, you can paste it to the file dd Or d to delete (CUT) the entire row where the cursor is located NDD cut down n columns where the cursor is located d1g Delete (CUT) all data from the row where the cursor is located to the first row of the file (useful) DG delete all data from the row where the cursor is located to the last row of the file YY copy the row where the cursor is located nyy number plus YY, copy down n rows of the row where the cursor is located. For example, for 4yy, copy all data from the row where the cursor is located to the first row of the file (useful) YG copies all data from the row where the cursor is located to the last row of the file. P sticks the cut data to the next column of the cursor (if one row is in the clipboard), next position (one character) p. paste the cut data on the cursor column J. Combine the column where the cursor is located with the data in the next column into a column

 

 

Related Article

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.