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

I would like to run a process in the background in Vim on Mac OS X (or Unix in general).

I would hope and expect the following, or some variant, to accomplish this:

execute "!my_command &"


!my_command &


!my_command \&

or some other alternative.

Unfortunately this does not seem to execute my_command at all. I would expect there to be some lightweight option.

One option would be to write a wrapper script that forks the command and exits, but I'm sure someone has done that already (GNU Parallel?).

What is the best way to accomplish this?

share|improve this question

migrated from Feb 12 '13 at 14:00

This question came from our site for professional and enthusiast programmers.

Works for me in cygwin... – n.m. Feb 11 '13 at 16:34
@n.m.: Thanks. It seems to be an escaping issue (ampersand not being properly escaped) with MacVim (and maybe only since MacVim 65?); others have encountered this in eg FreeBSD, but that solution does not work here. – Brian M. Hunt Feb 11 '13 at 16:35
up vote 7 down vote accepted

This might be because my_command needs a terminal to interact with. You could provide one with GNU screen or tmux, e.g.:

!screen -dm "my_command"


!tmux new -d "my_command"
share|improve this answer
Great idea. tmux worked as expected. Many thanks @Thor. – Brian M. Hunt Feb 11 '13 at 17:55

All of the commands below work as expected when executed in MacVim (snapshot 66), and I'm pretty sure they would work on my Ubuntu box at home:

!mplayer song.mp3 &
:execute "!mplayer song.mp3 &"
:call system("mplayer song.mp3 &")

If it doesn't work for you, you could try one of the few scripts that allow you to run asynchronous commands:

(and I just saw that Thor solved your problem)

share|improve this answer
Thanks romainl. At one point I could swear all the above worked for me as well, but they seem to have stopped for no apparent reason. Whatever the cause, before Thor's suggestion I also looked at the plugins you suggest but I thought they might be overkill for the given task — though the suggestion is appreciated. – Brian M. Hunt Feb 11 '13 at 18:15
Did you alter the shell or shellcmdflag option? – romainl Feb 11 '13 at 20:15
No; they are /bin/bash and -c respectively. – Brian M. Hunt Feb 11 '13 at 20:23

You must log in to answer this question.

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