I tried to replace if(cond1)
with if(cond1&&cond2)
in vim, so I typed the command
:%s/\Vif(cond1)/if(cond1&&cond2)/g
but the result is
if(cond1if(cond1)if(cond1)cond2)
and not
if(cond1&&cond2)
What command should I actually use?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityI tried to replace if(cond1)
with if(cond1&&cond2)
in vim, so I typed the command
:%s/\Vif(cond1)/if(cond1&&cond2)/g
but the result is
if(cond1if(cond1)if(cond1)cond2)
and not
if(cond1&&cond2)
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 \
:
%substitute/\Vif(cond1)/if(cond1\&\&cond2)/g