[Vim] Replace Using Regular Expression Group


Question

I want to turn the following texts:

C413 TYPE
C414 TYPE
C415 TYPE

into:

平鐵板 C413
平鐵板 C414
平鐵板 C415

How 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:

[1]vim replace with named group at DuckDuckGo
[2]Vim Regex Capture Groups [bau -> byau : ceu -> cyeu] - Stack Overflow