Some tips for using vim

Source: Internet
Author: User


Too simple to say, just find a manual can find, here to say some tips, but also recently used to force out of the study, hehe, but quite convenient.

1. Global replacement
(1) v + G + $ Select all, then enter: s/original string/target string/
(2):%s/original string/target string/

2. Clear the blank characters at the end of all lines in the page:
:%s//s/+$//

3. Clear All Blanks
:%s//(/s*/n/)/+//r/

4. Remove All//comments
:%s!/s*//.*!!

5. Remove All/*/comments
:%s!/s*//*/_./{-}/*//s*!!

6. Do some internal data repeat replacement
Sometimes we need to organize some batch of data to execute the command line, for example, we need to use the previous data to generate the following data, such as the data:
/var/database/aaa.txt
/var/database/bbb.txt
/var/database/ccc.txt

I would like to become a command, such as to become a copy of the commands, copied to the previous directory, then you can execute:
:%s//(. *base///)/(. */.txt/)/CP/1/2/.///2/

has become:
Cp/var/database/aaa.txt./aaa.txt
Cp/var/database/bbb.txt./bbb.txt
Cp/var/database/ccc.txt./ccc.txt

The key here is the use of the Sub mode: () in the middle,/1 represents the first found child mode,/2 for the second, and so on, vim inside () must be escaped, unlike other languages


7. Add comments (one operation applied on multiple lines)
such as the need to add # or is//this annotation:
Ctrl + V navigates to the start line, then selects the desired row, then execute the I command, then enter # or//, and press ESC two times to apply the annotation operation to all selected rows, remembering that the V directive should not be used, and that the CTRL + V should be used (to clear the comment to refer to the above method) (V is selected by row) , Ctrl + V is selected by column)

8. The Hyphenation
V to select the rows to be neat, enter = warping

9. Open multiple Windows
Use in vim: the SP file name opens the row window (horizontal), uses: The VSP file name opens the column window (vertical), uses: Q Closes the current window, uses: QA Closes all windows, uses Ctrl + W to switch in each window.
Maximized window: Ctrl + W activates a window, then SHITF +-maximizes
Change the window to the specified line height: Ctrl + w activates the window, 10 (the number of line sizes needed to be changed), Shift +-, performing changes
Increased number of Line heights: Ctrl + w activation window, 10 (need to increase the row size number), SHIFT + +, perform changes

10. String/Variable Hints
In the input state, press CTRL + P to display all the strings defined on this page, if you enter a string portion of the content, and then press CTRL + P to display all of the contents of the beginning of your input string. Press Ctrl + x in the input state to view all other methods that are valid

Reference URL:
http://www-128.ibm.com/developerworks/cn/linux/l-tip-vim1/
Http://man.chinaunix.net/newsoft/vi/doc/help.html

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.