Search code examples
ubuntuvimmultiple-instancesyank

Copy multiple lines and text until a space in VIM


I have to run a bunch of commands in a bash script and I want to echo which command is currently running:

I have this file (which is about 100 lines):

nohup command1 param1 param2
nohup command2 p1 p2
nohup cmd3 p1 p2 param3

I would like:

echo "Running command1" ; nohup command1 param1 param2
echo "Running command2" ; nohup command2 p1 p2
echo "Running cmd3" ; nohup cmd3 p1 p2 param3

I tried yank but it copy 1 line at a time, is there a way to copy all of the lines?


Solution

  • regex is what you need here:

    :%s/^\(nohup\) \([a-zA-Z0-9]*\)/echo "Running \2"; \1 \2/