Tips for using Vim

Source: Internet
Author: User

If it's too simple, you can find a manual. Here we will talk about some tips. It's also recently used to make it easy to learn.

1. Global replacement
(1) V + G + $ select all, and then enter: S/original string/Target string/
(2): % S/original string/Target string/

2. Clear the blank characters at the end of all rows on the page:
: % S/+ $ //

3. Clear all white spaces
: % S // (/S */n/)/+ // R/

4. Remove all // annotations.
: % S! /S *//.*!!

5. Remove all/**/comments.
: % S! /S */_./{-}/*/S *! !

6. Repeat some internal data
Sometimes we need to organize some batch data for command line execution. For example, we need to use the previous data to generate the subsequent data, such as the data:
/Var/database/aaa.txt
/Var/database/bbb.txt
/Var/database/ccc.txt

I want to change to commands one by one, for example, to copy commands one by one, but to the former directory, You can execute:
: % S // (. * base //)/(. */. txt/)/CP/1/2/. // 2/

Changed:
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 submode: () in the middle,/1 indicates the first submode found,/2 indicates the second, and so on. The () in VIM must be escaped, different from other languages

7. Add comments (one operation is applied on multiple rows)
For example, you need to add the # Or // annotation:
CTRL + V locate the start line, select the desired line, then execute the I command, enter # Or //, and press esc twice, you can apply the annotation operation to all selected rows. Remember that the V command cannot be used for selection, but Ctrl + V should be used. (To clear the annotation, refer to the above method.) (V is selected by row, CTRL + V is selected by column)

8. Align
V select the rows to be neatly organized and enter = to normalize

9. open multiple windows
In vim, use: SP file name to open the row window (horizontal), use: VSP file name to open the column window (vertical), use: Q to close the current window, and use: QA to close all windows, use Ctrl + W to switch between windows.
Maximize window: Ctrl + W to activate a window, and then shitf +-to maximize
Change the window to the specified Row Height: Ctrl + W to activate the window, 10 (number of the row size to be changed), Shift +-, and change
Increase the height of several rows: Ctrl + W activation window, 10 (number of rows to be added), shift ++, and change

10. String/variable prompt
In the input content status, press Ctrl + P to display all strings defined on this page. If you enter part of the string, press Ctrl + P to display all the content starting with the string you entered. Press Ctrl + X in the input state to view all other valid methods.

 

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.