Vim: String substitution

Source: Internet
Author: User

: s/str1/str2/replaces the current line the first str1 is str2
: S/str1/str2/g replaces the current line with all str1 as str2 (note that the S/XX/XXX/G statement starts with S and the middle space is treated as part of the string)


: N,n2 s/str1/str2/replaces the nth row start to the first str1 of each row in line N2 str2
: N,n2 s/str1/str2/g replaces the nth line to the N2 row, and all str1 is str2 for each row
N is a number, and if N is., represents the current row. If N2 is $, the last line is indicated.


:% s/str1/str2/replaces the first str1 of each line as str2
:% s/str1/str2/g replaces all str1 in each row as str2

You can use # as a delimiter, at which time the middle/not as a delimiter
: s#str1/#str2/# Replace the current row the first str1/is str2/




Summarize the above substitution commands:
1. G At the end of the command:
Plus g, which indicates that each occurrence of the search string is replaced;
No g, which means that only the first occurrence of the search string is replaced;
2. Multi-line Replacement:
Sentence First Plus: n,n2
3. Full-text replacement:
First sentence plus:%
Sentence First Plus: 1,$
4. Use # as a delimiter to let/also be part of a string.
Use/As a delimiter, you can make # also as part of a string.
They just complement each other.

Vim: String substitution

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.