1

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.

3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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