I tried to replace if(cond1) with if(cond1&&cond2) in vim, so I typed the command


but the result is
if(cond1if(cond1)if(cond1)cond2) and not

What command should I actually use?


& in a replacement is a bit special:

magic  nomagic  action
  &      \&     replaced with the whole matched pattern      *s/\&*

But you can escape it with \:

| improve this answer | |
  • it works, thanks a lot! – HaraInanba Sep 16 at 13:30

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.