Because &
is special in the replacement part (it means "the whole matched string"), you have to escape it:
:%s/&&&&&&&&&/\&/g
(Note the backslash before &
in the replacement part.)
Question
How do I substitute &&&&&&&&&
with &
? I have tried :%s/&&&&&&&&&/&/g
but i only get more &
.
Solution
Because &
is special in the replacement part (it means "the whole matched string"), you have to escape it:
:%s/&&&&&&&&&/\&/g
(Note the backslash before &
in the replacement part.)
OTHER TIPS
You must escape &
in the replacement section. Unescaped, &
refers to the whole match.
:%s/&&&&&&&&&/\&/g
You need to escape &
with \
in replace string
:%s/&&&&&&&&&/\&/g
In replace string, &
has a special meaning and contains matching string.
Therefore in you case, you are replacing nothing but match itself hence no change.
If your intension is to replace multiple &
with a single one, then try following
:%s/&\+/\&/g
You need a quantifier in the expression:
:%s/&\+/&/g
not sure if it works like that in vim, it is default regex, the plus sign tells it should capture any combination of one or multiple '&' signs, using &{9} should find exactly nine