Android extended series (4)-basic use of the vim Editor

Source: Internet
Author: User

I have been in touch with Linux for several years. I feel that Linux has been separated by minutes and is full of regrets. One of the biggest regrets is that I have never been proficient in Vim, it cannot fully adapt to Code development under vim.
I think it is necessary to summarize the use of VIM in my recent work.
however, I cannot describe how to use all Vim commands. Instead, I think it is more effective to describe the operation commands commonly used for editing Android or Java.

1. Three command modes of VIM
(1). Command mode:Used to enter commands and make simple changes
(2). insert mode:Used to insert text and modify text
(3). Last line mode:It is used to input commands, perform visualized operations, and search and replace operations.
After getting familiar with these three modes, the editing + toolbar (or menu bar) in Windows is an important way for us to enter the command interface, I believe everyone will like this operation mode.
You can switch between the three modes as follows:
(1) switch from command mode to insert mode:Enter the text INSERT command.
Text insertion Commands include: I, I, a, a, O, O
(2) Exit from the command mode in the insert mode.:ESC.
(3) enter the last line mode in command mode:Colon:.
For example, set nu indicates that the row number is displayed.
: Set Nonu cancel row number display
(4) Exit from the last line mode to the command mode.:Enter or ESC.
From this we can also see that the command mode is also a pivot here, which is very important.

2. text insertion command
As we mentioned above, the text insertion command is just as we can.
The text insertion command mainly includes the I, I, a, a, O, O.

I (insert) insert text before the cursor I insert text at the beginning of the row where the cursor is located a (append) insert text after the cursor a add text at the end of the row where the cursor is located O (open) add a line under the row where the cursor is located. o add a line above the row where the cursor is located.

To tell the truth, these commands are really useful and must be mastered. I recommend that you remember the lower-case commands first, regardless of the upper-case commands. After you become familiar with the latter, you will naturally remember the upper-case commands.

3. Exit and save Vim
Exiting Vim also involves the following commands:

 
: Q: Exit vim and return to shell. If any modification is not saved, VI will prompt at the end of the line that it will not exit Vim to shell: Q! Exit vim and return to shell. Discard unsaved changes: WQ is saved first, and then exit Vim. Return to shell and WQ. The function is similar. The difference is that if the file is not modified, X does not update the modification time of the file, while WQ updates the modification time of the file, whether or not there is any modification. : W filename: Write the current file to the filename File

WQ and X should be used a lot.

4. Common commands in command mode
The most common commands in command mode include Delete, copy, paste, undo, and move. The following are some of the most common operations:

Dd Delete the current row 5dd Delete the current row down 5 rows x Delete the cursor character x Delete the pre-cursor character YY copy the current line 5yy copy the current row down 5 rows P paste U cancel hjkl move cursor in the upper left and lower right direction ^ move cursor to the beginning of the line $ move cursor to the end of the line Gg jump to the first line of the file 5gg jump to 5th rows g jump to the end of the file Ctrl + F roll back one page. CTRL + D roll back half page. CTRL + B roll forward one page. CTRL + u roll forward half page. CTRL + e scroll down a line. CTRL + y roll up a row.

These commands are frequently used to edit files. They must be mastered and are very useful.

5. search and replace

 
/Android searches for Android. If n is used, it indicates downward search. If n is used, it indicates upward search? Android searches for Android devices. If you press N, it indicates to search up. If you press N, searches SHIFT + 8 backward for the word pointed by the current cursor SHIFT + 3 forward for the word pointed by the current cursor: % S/old/new/g Replace "old" in the buffer zone of the editor with new: s/old/new/g Replace "old" of lines 19 to 20 of the file with new

It is quite convenient to search and replace with vim.

6. Summary
The above is the basic usage of the vim editor. I will write it here to make a summary and share it with you.

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.