Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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 &&
...
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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