Duncan Betts Duncan Betts - 2 months ago 8
Bash Question

Insert Multiple Line Quote Multiple Times

I'd like to take this:

system_info
show_uptime
drive_space
home_space


And paste this:

() {

}


to end up with this:

system_info()
{

}

show_uptime()
{

}

drive_space()
{

}

home_space()
{

}


I've tried using visual mode, but to no avail.

Help much appreciated!

Answer

You could use a substitution:

:%s/$/() {\r\r}\r

Where we substitute each end-of-line $ in the whole buffer % with:

  • a pair of parentheses,
  • followed by a space,
  • followed by an opening brace,
  • followed by two line breaks,
  • followed by a closing brace,
  • followed by a line break.

Or you could simply paste your snippet at the end of each line with p.