Vim uses ---- global replacement

Source: Internet
Author: User

General replacement

S/old/new--- Replace the first matching item of the current row

S/old/new/g---- Replace all the matching items in the current row

Number1, number2-s/old/new/g---- Replace all the matching items from the number1 row to the number2 row

1, $ S/old/new/g = % S/old/new/g----- Replace all matching items of the entire file

Confirm and replace

Add a C (confirm) after the replacement command, for example, 1, 30 s/his/The/GC. Each time you find the matching item, you will be prompted whether to replace it. Enter y, enter to confirm the replacement, and enter to skip the replacement.

Replace context-sensitive with g/pattern/S/old/new/g

The first G indicates that pattern needs to be searched from all rows, and the following G indicates that all matching items of the current row are replaced.

If pattern and old are the same, old can be omitted. This command is equivalent to % S/old/new/g.

Regular Expression matching rules

.---- Match all characters except line breaks

*---- Match 0 or multiple characters

^---- Match the beginning of a row

$---- Match the end of a row

\---- Anti-Italian character, indicating that the subsequent character is a regular character.

\(\)--- Placeholder. A maximum of 9 placeholders can exist in a row. For example, if \ (that \) or \ (this \) \ (that \) is set to 1, use that to replace \ 1, \ (this \) it is called by \ 2. For example, if you replace that or this with this or that, you can use the command % S/\ (that \) or \ (this \)/\ 2 or \ 1.

\ </>---- Match a word that starts or ends with a character. For example, \ <AC matches a word that starts with AC, and AC/> matches a word that ends with AC.

~---- Match the previous Regular Expression in the search. For example, if you want to start searching for/The, you can use /~ N to replace/then

Vim uses ---- global replacement

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.