Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 &"

or

!my_command &

or

!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 stackoverflow.com 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

2 Answers 2

up vote 6 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"

Or:

!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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.