Vim string replacement and vim string replacement

Source: Internet
Author: User

Vim string replacement and vim string replacement

In the project test of the company, you need to modify the multi-path in the vi editing. At this time, you have used the string replacement knowledge. Here I have sorted it out myself.

I. Basic Content replacement without special symbols

  • : S/old/new/Replace the first old value of the current row with new. If the new value is left blank, editing is not affected.
  • : S/old/new/g replace all old values of the current row with new
  • : N, $ s/old/new/Replace the first old value from row n to row n as new
  • : N, $ s/vivian/sky/g to replace all the old values from row n to the last row. Here, there is no space between $ and s, personal habits: space (n is a number, if n is ., starting from the current row to the last row)
  • : % S/old/new/(equivalent to: g/old/s // new/) Replace the first old of each row with new
  • : % S/old/new/g (equivalent to: g/old/s // new/g)

Ii. Replacement of special characters

  • : S # old/# new/# Replace the first old/of the current row with new/
  • : 1, $ s #/old/#/new/# replace all the existing strings in the body with the string new/

Iii. self-testing

  • : 1, $ s/new/old =: 1, $ s/new/old/g =: % s/old/new/g. The effect of changing the strings is the same.

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.