Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the replacement command in Vim

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Today, I would like to talk to you about what the replacement command in Vim is. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something from this article.

Grammar

Vim can use the: substitute command to replace specified characters with other characters, usually in the abbreviated format of the command: s. Borrowing regular expressions can achieve richer replacement functions, and the basic syntax is:

: [range] s / source string / target string / [option]

Range and option can be left unfilled by default, and each field means:

Range: represents the scope of retrieval. The default is the current line search, 1jin10 represents lines 1 to 10,% represents the entire file, which is equivalent to 1 line, while $represents from the current line to the end of the file

Abbreviation for s:substitute, which stands for replacement

Option: represents the operation type. By default, only the first matching character is replaced by default. G (global) global replacement, c (comfirm) operation confirms that I (ignorecase) is not case-sensitive. These options can be used in combination.

For example, the following command will display the text that will be changed and ask for confirmation:

: 1 the with foo with foo (y/n/a/q/l/ E / Y)

At this point, you can choose the following actions:

Y Yes: perform this replacement n No: cancel this replacement an All: perform all replacements without asking Q Quit: exit without making any changes l Last: exit CTRL-E after replacing the current match point CTRL-Y tumble up one line practical case

1. Replace aa with bb in all strings containing aa that appear on the line of the cursor

: s/aa/bb/g

two。 Replace aa with bb in all strings containing aa that appear in the document

:% s/aa/bb/g

3. Replace aa with bb in all strings containing aa that appear from lines 12 to 23

: 12,23s/aa/bb/g

4. The full text begins with a # character, which is very useful when commenting in batches in Python

:% s / ^ / # /

5. Delete all extra spaces at the end of the line

:% s = * $=

6. Delete all blank lines, where g means to replace all strings that meet the requirements in the article, ^ indicates the beginning of the line, and $indicates the end of the line

: G / ^ $/ d after reading the above, do you have any further understanding of what the replacement command in Vim is? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report