I'm trying to search and replace " &" (space character and & character, without quotation marks) with "& " (& followed by space).
I tried :%s/ &/& /g
as well as /\s&/
and /\ &/
but none of these seem to pick up the first space. Is there something I'm missing?
In vim regular expressions, '&' is a special character that means "the whole matched pattern", so "& " is expanding to " & ". To fix this, escape the &:
:%s/ &/\& /g
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With