I'm trying to edit a config file and want to add a specific line of code (on a newline) whenever a specific string is matched...everything I've searched for does search and replace, I'm looking for search and append...
personally, i think using ":g" command is probably better than ":s" for this problem.
:g/key/norm owhat ever you want
will make text:
foo
bar
key
foo2
bar2
key2
blah
to:
foo
bar
key
what ever you want
foo2
bar2
key2
what ever you want
blah
if you want to add the new line above the line containing the pattern, just change the small "o" to "O".
In vim
\r
is the new-line. So you can do something like this
%s/search string/&\rnew code/
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