문제

How do I substitute &&&&&&&&& with &? I have tried :%s/&&&&&&&&&/&/gbut i only get more &.

도움이 되었습니까?

해결책

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.)

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top