pachun
pachun

Reputation: 920

vim search and replace with the effect of reformatting some middle characters

So, so I have this in some file:

ABCxxx.yyyDEF

and I want to change it to be:

HELLOxxx.yyyWORLD

Is there a way to do this? / How?

I was playing with using wildcards, e.g.

:%s/ABC.*DEF/HELLO.*WORLD/g

but, .* in the replaced HELLO_WORLD doesnt save the replaced .* characters. It just comes out as HELLO.*WORLD

Help appreaciated,

Pachun

Upvotes: 0

Views: 146

Answers (1)

s/ABC\(xxx.yyy\)WORD/JJJ\1MOO/

Whatever is in \(\) will be remembered and can be used in the replacement string.

see: vim regex backreference

Upvotes: 3

Related Questions