Vim usage Summary

Source: Internet
Author: User

It has been nearly a year since vim was used to summarize the use of vim, but it is always a half hour without interruption. Recently, I 've been wandering around the terminal, so I will make a summary of the simple use of vim. After all, you cannot forget the key features. Vim is an excellent program editor in the terminal environment. First, let's talk about vim's three modes: general mode, edit mode, and command mode. Normal Mode: you can move the cursor, delete, select, copy, and paste the cursor, and perform other operations. Edit mode: Enter "I, o, a, r" to enter the edit mode. The input "I, o, and a" enters the insert mode, which is similar to the editor operation in the graphic interface environment, but the cursor position is different in the initial situation; enter "r", which is the replacement mode, that is, the character where the cursor is replaced. Command mode: In normal mode, enter ":,/,? "You can move the cursor to the bottom of the terminal. In this case, you can enter the relevant configuration commands set by vim. As there are no buttons such as graphical interfaces in the terminal, you can only save files and open new files in the form of commands. Of course, there are also vim configurations. Note: The vim mode can only be switched between the general mode <-> edit mode and general mode <-> command mode. I thought that I had to press vim to enter the editing mode for the first time, but I had no idea how to jump out of the results. Finally, disable the terminal forcibly. The experience of using vim is: Once you are familiar with most of the usage skills, you will not be able to extricate yourself; maybe you will no longer be able to adapt to other text editors. Of course, it would be better if vim has the ability to automatically fill in. The button operation indicates that the cursor's moving hjkl-> top left, bottom, right => I really cannot understand this setting. How nice would it be to move the cursor with most game wdsa! Maybe it's because I have a lot of games, maybe after I got in touch with vim. [Ctrl] + f/B/d/u indicates moving one or half pages. + Move the cursor to the next line without a space character.-move the cursor to the previous line without a space character. N + [space]: n indicates the number you entered. The cursor moves to the right to the nth character. 0 or [home], move the cursor to the beginning of the row where the cursor is located (at the first character ). $ Or [End] key to move the last character of the row where the cursor is located. => Where is the [end] key? H/M/L or High, middle, or low! That is, move the cursor to the first, middle, and last line of the page. G move the cursor to the last line of the file; nG move to the nth line of the file; gg move the cursor to the first line; n [Enter] move the cursor down n rows. Search and replace these operations are mainly executed in command mode. /Word indicates the string to be searched. It is searched down by the cursor ;? Word is searched up by the cursor. N/N repeat the search operation, and N changes the search direction.: N1, n2s/word1/word2/g is located between the n1 and n2 rows. Find the string word1 and replace word1 with word2.: 1, $ s/word1/word2/g searches for replacement between the first row and the last row; 1, $ s/word1/word2/gc replace operations require confirm processing. Delete, copy, and paste x to delete one character. X to delete one character. nx to delete n consecutive characters. Dd deletes the row where the cursor is located; ndd deletes n rows down the cursor. Yy: copy the row where the cursor is located; nyy: copy the n rows down the cursor. P paste the copied content in the next line of the cursor; P paste the copied content in the previous line of the cursor. Content Selection | block selection v is selected from the cursor up or down. [Ctrl] + v block selection, in the form of a rectangle. Y copies the selected content to the memory. d deletes the selected content. Some other important commands u undo the previous operation; [Ctrl] + r repeat the previous operation. In normal mode, enter the insert mode. I \ I: I is the current cursor, And I is the first non-Space Place in the current row. A \ A: a is the next character of the current cursor. A is inserted from the last character of the row where the cursor is located. O \ O: Insert a new row into the next row of the row where o cursor is located, and Insert a new row into the last row of the row where O cursor is located. R \ R: Replace the character where the cursor is located. After the replacement, return to normal mode. If r replaces the character where the cursor is located, it is returned to normal mode only after pressing [ESC. Save frequently-used command files in command mode: w/w!! Indicates that the mandatory meaning w + filename is saved. N1, n2 w + filename indicates to save the contents of the row to the file filename. R + filename Add the content in the file filename to the row where the current edited content cursor is located.! + (Commands on linux terminal) temporarily exit vim, execute linux terminal commands, and display the results in vim. => This is my favorite feature. Q \ ZZ exits vim. => Beginners have never known how to exit vim.

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.