Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I run Unix commands while I'm inside vim?

share|improve this question

Go to command mode Esc, then run :!unix_command. Anything run from the : prompt starting with a bang ! will be run as a unix shell command. You'll be shown the output and allowed to hit a key to get back to your work in vim.

If you have text selected in visual mode and want to send it TO a command as STDIN, hit !! and enter your command. The results of the command will replace the text you have selected.

share|improve this answer
5  
Also, !! without any text selected will let you run a command and then insert the result at your current cursor position -- no need to send stuff to STDIN and replace it if you don't need/want to. – Kromey May 18 '11 at 23:36
1  
also, if you simply want to put the output of a command in your document, simply do :r!unix_command. This is usefull for commands such as date – Yab May 19 '11 at 6:01
    
You can also execute multiple lines of your vi buffer by the shell (or any interpreter) and have them replaced by the result of the execution. eg: :10,20!sh or, form marked lines, 'a,'b!sh – jlliagre May 19 '11 at 11:58

From a VIM help mirror:

:shell        :sh[ell]        start a shell
:!            :!{command}     execute {command} with a shell
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .