StatGenGeek StatGenGeek - 1 year ago 83
Bash Question

Execute a line of text in bash from a vim document

I don't think this question has been answered.

I know that I can get into bash while in vim via:







and then use bash commands as normal, and get back out using fg.

What I am wondering is, can I execute a line of code from a script in vim straight to Bash, say in a separate buffer, without having to copy it (via highlighting in visual mode for example) from vim, then going to a terminal and pasting it and hitting enter etc.?

i.e. is there a nice quick vimmish way of doing this without all the fluff?

Answer Source

Arguably easiest way:

  1. Yank the text you want to execute.
  2. Open the cmdline (by pressing :)
  3. type ! and then press ctrl-r and ", which will paste the content of the unnamed register to the cmdline (which will contain the text you wanted to execute)
  4. press Enter
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download