Reputation: 1869
How do I substitute &&&&&&&&&
with &
? I have tried :%s/&&&&&&&&&/&/g
but i only get more &
.
Upvotes: 2
Views: 103
Reputation: 11703
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
Upvotes: 4
Reputation: 31
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
Upvotes: -3
Reputation: 26501
You must escape &
in the replacement section. Unescaped, &
refers to the whole match.
:%s/&&&&&&&&&/\&/g
Upvotes: 4
Reputation: 1074295
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.)
Upvotes: 5