Implement bulk substitution of strings in VI

Source: Internet
Author: User

implement bulk substitution of strings in VI

A. Replace all in the file:


%S#ABC#DEF#G (replace all ABC in the file with Def)


For example, replace All "linuxidc.com" in a text file with "Linuxidc.net":


:%s#linuxidc.com#xwen.net#g (if there is a # in the file, available/replace, e.g.:%s/linuxidc.com/xwen.net/g)


B. Local replacement in the file:


Replace All "abc" in lines 10 through 50 with "Def"


: 10,50s#abc#def#g (if there is # in the file, available/replace,:%s/abc/def/g)


If the above command is appended with C after G, the prompt will be displayed to the user to confirm (conform) if replacement is required before replacing. Like what

:%S#LINUXIDC.COM#LINUXIDC.NET#GC



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Implement bulk substitution of strings in VI

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.