How can I run a terminal command (for instance build) in vim while working on a file, while simultaneously showing the output live in a vsplit?

  • Have a look at github.com/tpope/vim-dispatch – taketwo Dec 7 '18 at 8:14
  • thanks, ill have a look at it, I just thought I heard vim now supports asynchronous tasks by default – user2741831 Dec 7 '18 at 8:17
  • Yes it does, @philosopher.stoned gave an example. The plugin just wraps around this functionality (and provides fallback for old Vim versions). In my opinion it has a nice interface and is easier to use than raw Vim commands. – taketwo Dec 8 '18 at 9:12
  • dokes this also work in gvim? cuz it says I need tmux – user2741831 Dec 8 '18 at 14:32

You need to use job_start function for this. It'll invoke your command in a separate process instance. You can pass buffer names to this call and vim will link STDOUT and STDERR pipes of job's process to these buffers. A host of additional actions are also possible, like registering callbacks when data is posted to these buffers, type of job being run, etc.

        let logjob = job_start("tail -f /tmp/log",
                             \ {'out_io': 'buffer', 'out_name': 'dummy'})
        vsplit | buffer dummy
  • this works really well, thanks. Is there a way to always keep the buffer at the very end to always see the output – user2741831 Dec 8 '18 at 21:15
  • Use vim movement command 'G' to go to end of buffer. Once at end, it'll always track new data being added and scroll automatically. – philosopher.stoned Dec 14 '18 at 8:35

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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