Nadav
Nadav

Reputation: 698

VIM S&R - using backref in the searched pattern

I want to search and replace something like this:

"foo : foo"

to

 "foo"

But of course, I need to that with a regex.

I have tried to use the below S&R command, but it seems that using backref in the searched string is not working:

%s/\(a-z\)\zs : \1\ze//

Any idea how can I do that?

Thanks.

Upvotes: 0

Views: 58

Answers (1)

phd
phd

Reputation: 94483

%s/\([a-z]\+\)\zs : \1\ze//

[a-z] means "any character", \+ means "repeated 1+ time".

\1 works perfectly!

Upvotes: 2

Related Questions