Detailed explanation of replacement operations in vi in CentOS

Source: Internet
Author: User

You can use commands to quickly Replace text when editing files using vi. The following describes some of its modes.

Replace the first OLD value of the current row with NEW: s/OLD/NEW, and replace the OLD value with NEW: s/OLD/NEW. replace all OLD values in the current file with NEW: % s/OLD/NEW/g

In addition to the above replacement modes, you can also specify two row numbers and replace all the OLD values between them with the NEW ones,

The syntax is: the first # indicates the start line, and the second # indicates the end line: #, # s/OLD/NEW/g replaces the OLD from the third row to the fifth row with NEW: 3, 5S/OLD/NEW/g where two rows can also appear only one, omitted that represents the row where the cursor is located, for example ::, 5S/OLD/NEW/g replace all OLD with NEW: 5, s/OLD/NEW/g replace all the OLD rows from row 5th to the row where the cursor is located with NEW. In addition, the last row can be represented by $. Therefore, % s/OLD/NEW/g is equivalent: 1, $ s/OLD/NEW/g


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.