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 :!)
  • Simple solution to a simple problem: run that command in another shell. – romainl Mar 28 '14 at 23:30
  • Making explicit all your requirements is always a good idea. – romainl Mar 29 '14 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 '14 at 22:38

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.

| 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 Ravenwolfe Mar 28 '14 at 22:45
  • Sorry, I missed the point about output. Edited my answer to address this ;) – s.wagner Mar 28 '14 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 '14 at 2:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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