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

How to implement the replacement function in Vim

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

Share

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

This article mainly explains "how to achieve the replacement function of Vim". Friends who are interested may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "how to achieve the replacement function of Vim"!

Vim can use regular expressions to achieve rich replacement functions. Its basic syntax is: [addr] s / source string / destination string / [option]. We can see that addr and option can be left unfilled by default. Their fields mean:

[addr] represents the scope of retrieval, the default represents the current line, 1 line 10 represents 1 to 10 lines,% represents the whole file equivalent to 1 line, and $represents the current line to the end of the file

S stands for substitution

Option represents the type of operation. By default, only the first matching character is replaced, g for global substitution, c for confirmation during operation, and gc can be used in combination.

Here are a few examples.

: s/aa/bb/g replaces aa with bb in all strings containing aa that appear on the line of the cursor

:% s/aa/bb/g replaces aa with bb in all strings containing aa that appear in the document

: 12 aa 23s an aa BBG replace aa with bb in all strings containing bb that appear from lines 12 to 23

:% s / ^ / # / add # characters at the beginning of the full text, which is very useful for batch comments

:% s = * $= remove any extra spaces at the end of all lines

G / ^ $/ d the g here means to replace all the strings that meet the requirements in the article, ^ means the beginning of the line, $represents the end of the line, the whole meaning is to delete all blank lines.

At this point, I believe you have a deeper understanding of "how to achieve the replacement function of Vim". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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