Use Vim (1): Basic commands

Source: Internet
Author: User
1. Vim Mode
Vim has three modes: general mode, edit mode, and command line mode.
2. General Mode
Open a file with vim and enter the normal mode. In this mode, you can delete characters and lines and copy and paste the file data.
2.1 move the cursor
H: Forward to the left of the character J: forward to the next character K: forward to the next character l: → to the right of a character the above four can be combined with numbers use 10j, down to 10 characters, 20l: 20 characters to the right. CTRL + F flip one page down CTRL + B Move to previous page Ctrl + D move down half page Ctrl + u move up half page N + spaces such as 5 spaces move five characters to the right 0 move the first line $ move the row at the end of H, move the first character m at the top of the screen to move the first character m in the middle of the screen l move the first character g at the bottom of the screen to the end of the file ng n is a number, move to row n Gg to move to file start N + enter n to number, move n lines down
2.2 search and replace
/Word search down word? Word lookup wordn repeat previous lookup n repeat previous lookup, reverse lookup: N1, N2s/word1/word2/g N1, N2 is a number, from N1 to N2 rows, replace word1 with word2: 1, $ S/word1/word2/g from the first row to the last row, replace word1 with word2: 1, before $ S/word1/word2/GC replacement, check whether the confirm needs to be replaced.
2.3 Delete
X deletes a character X [backspace] and deletes a character nx n as a number, and deletes n characters dd to delete the current row ndd n as a number, delete n rows of d1g Delete cursor to first row DG Delete cursor to last row d $ Delete cursor to end of line character D0 Delete cursor to line first character
2.4 copy and paste
YY copies the current row nyy N as a number, copy the next n rows of y1g copy from the first row to the current row YG copy the current row to the last row y0 copy the character y between the beginning of the row and the cursor $ copy the character p between the cursor and the end of the row paste P to the next row and paste J to the previous row. merge the current row and the next row into one row.
U restore the last operation. Reset Ctrl + R to redo the previous operation. Redo. decimal point. Repeat the previous operation.
3. editing mode
To edit the text, press I, A, and so on. The insert or replace character appears in the lower left corner. Enter the edit mode command: I insert at the cursor position I insert the first non-null character in the current row out insert a cursor next character start a last character in the row start insert O next line start o previous line start R replace the cursor character, run the R command once to replace the character of the cursor until ESC exits.
[ESC] Ctrl + C Exit the editing mode and enter the normal mode
4. Command Line Mode
In normal mode, enter :,/,? , One of the three, the cursor will go to the bottom, enter the corresponding command. Save files, exit vim, and set Vim environment variables. : W save file: W! Force save: Q exit VIM: Q! Exit and do not save the file: Exit WQ and save the file ZZ. If the file is not changed, exit and save it. If the file is changed, exit and save: W filename file as filename: R filename to read the content of another file, append the line N1, N2 W filename N1 to the row N2 and save it to another file :! Command to execute the command, such as ":! Ls-L "to list the current directory files
Set environment variable: Set nu display row number: Set Nonu do not show row number
Address: http://blog.csdn.net/yonggang7/article/details/38148075

Use Vim (1): Basic commands

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.