You can use \r
to represent a newline in :substitute
patterns:
:%s,source /PATH/TO/OLD/ENV.sh,source /PATH/TO/NEW/ENV1.sh\rsource /PATH/TO/NEW/ENV2.sh/,
Note that in substitute patterns \n
means NULL byte, not newline. This is inconsistent and confusing (I'm not sure what the reason for it is, it's a vi quirk you'll just have to remember)
I used ,
instead of /
to avoid having to escape all the /
s in the path; see What does it mean to replace slashes (/) by exclamation marks (!) in a substitute command?
You can use the :bufdo
, :windo
, and :tabdo
commands to run any command on multiple buffers, windows, or tabs. For example:
:bufdo :%s,source /PATH/TO/OLD/ENV.sh,source /PATH/TO/NEW/ENV1.sh\rsource /PATH/TO/NEW/ENV2.sh,
:wa
Which should do what you want.
:substitute
command is incredibly similar to sed's. See:h :s
. For multiple files, see:h :argdo
and:h bufdo