I have a list of variables I want to compare in the form

 acceptEncoding == copy.
 authorization == copy.
 cacheControl == copy.
 contentEncodin == copy.
 contentLength == copy.
...

and I want to turn it into

acceptEncoding == copy.acceptEncoding &&
authorization == copy.authorization &&
cacheControl == copy.cacheControl &&
contentEncodin == copy.contentEncoding &&
contentLength == copy.contentLength &&
...

using :%s in vim. I used the command as %s/(.+) == copy\./\1 == copy.\1 &&/ but it's not matching any of the instances, yet the regex seems to be correct and works in regex buddy / other regex applications, is there something special about vim :s regex that makes this not work? I've already just went ahead and did it with a macro but I want to know why the regex was failing.

link|improve this question
feedback

1 Answer

up vote 3 down vote accepted

You need to escape ( + ) &

%s/\(.\+\) == copy\./\1 == copy.\1 \&\&/

This should yield :

acceptEncoding == copy.acceptEncoding &&
authorization == copy.authorization &&
cacheControl == copy.cacheControl &&
contentEncodin == copy.contentEncodin &&
contentLength == copy.contentLength &&
...
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.