Use vim (1): Basic commands

Source: Internet
Author: User

Use vim (1): Basic commands
1. vim has three modes: Normal Mode, edit mode, and command line mode. 2. In normal mode, use vim to open a file and enter normal mode. In this mode, you can delete characters and lines and copy and paste file data. 2.1 move cursor h: cursor to the left one character j: cursor to the next character k: cursor up one character l: → to the right one character above four can be combined with numbers use 10j, the name can be 10 to 20 characters in length and 20 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 line n gg to move to file start n + Enter n as number, move down n rows 2.2 find and replace/word search down word? Word lookup word n 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 delete a character X [Backspace] forward delete a character nx n as a number and delete 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 copy 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 and redo the previous operation. decimal point, repeat the previous operation 3. in editing mode, you need to edit the text by pressing 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 the 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. In the 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

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.