4
[Vim] Replace Using Regular Expression Group
source link: http://siongui.github.io/2018/12/01/vim-replace-using-regular-expression-group/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
[Vim] Replace Using Regular Expression Group
December 01, 2018
Question
I want to turn the following texts:
C413 TYPE C414 TYPE C415 TYPEinto:
平鐵板 C413 平鐵板 C414 平鐵板 C415How to do it in Vim editor?
Answer
I know that regular expression groups can help me solve the problem, so I make some DuckDuckGo search [1] and found that someone have the same problem as me [2]. I follow the example and come up with my own answer:
:%s/\(C\d\d\d\) TYPE/平鐵板 \1/gc
Tested on Ubuntu Linux 18.04, vim 2:8.0.1453-1ubuntu1.
References:
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK