In Vim regular expression, I know it is possible to replace foo by bar on all lines starting with % using
:g/^%/s/foo/bar/g
but I want to replace foo by bar on all lines NOT starting with %. Is there a way to easily do so?
Try :vglobal:
:v/^%/s/foo/bar/g
You can just negate the % character using character class: -
:g/^[^%]/s/foo/bar/g
[^%] match any character except %, at the start of the string.
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