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.

When executing a shell command in VIM, it waits for the command to finish. You can press Enter to switch back to VIM, but it will only switch back after the command has finished. In the event of a longer running shell task, it would be more advantageous to go back to VIM to keep working, and check in on the shell output later.

What is the simplest way to:

  1. Run a Shell Command (:!jshint %)
  2. Switch back to VIM before the command has finished.
  3. Check back in on the output later. (The easiesy way I've found is :!)
share|improve this question
    
Simple solution to a simple problem: run that command in another shell. –  romainl Mar 28 at 23:30
    
Making explicit all your requirements is always a good idea. –  romainl Mar 29 at 11:22
    
Both :!jshint % and :!node server.js can be done in Vim. The first one must be run from Vim because of the % (so the "another shell" route is forbidden) but the second one doesn't (so the "another shell" route is clear). Since your question doesn't specify anything that would tie your long_running command to Vim, using another shell is a totally valid (and much cleaner) alternative that satisfies all the requirements in your question. –  romainl Mar 29 at 22:38

1 Answer 1

up vote 6 down vote accepted

You can execute any command, just as in a normal shell with & to send it to the background:

:! (long_running command) & 

and return back to vim.

Though you should note, that if the commands do output something, it will make vim look messy. If your command doesn't output anything, I think you should be fine.

If your command does output text, you might consider either:

:! (long_running command >output 2>&1) &

if you want to have stdout as well as stderr in one file or

:! (long_running command >output.stdout 2>output.stderr) &

if you want them be in separate files.

share|improve this answer
    
Thanks Neocrow, checking back in and reading the output later is definitely a requirement, as listed in bullet 3. I would say the messyness makes this solution relatively unusable for my case. –  Joseph Jaber Mar 28 at 22:45
    
Sorry, I missed the point about output. Edited my answer to address this ;) –  neocrow Mar 28 at 22:54
    
Might also want to mention that for the same effect on windows, you would do :!start (long_running command) –  sbell Mar 29 at 2:06

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.