In vi, how to replace the first character in each line if it is the specified character a
with another character !
? If the first character is space,do not do anything.
Global substitute the first character of a line if it is 'a':
:%s/^[a]/!/
Global substitute the first character of a line if it is not space:
:%s/^[^ ]/!/
Or using global command :g
:g/^a/s//!
this will automatically skip all lines that begin with a space or a character that does not match ^a
and replace all matching with !
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