skywind3000 / asyncrun.vim

:rocket: Run Async Shell Commands in Vim 8.0 / NeoVim and Output to the Quickfix Window !!
https://www.vim.org/scripts/script.php?script_id=5431
MIT License
1.84k stars 109 forks source link

Feature: Run in a terminal, but send output to quickfix? #262

Open wookayin opened 1 year ago

wookayin commented 1 year ago

The -mode=? option allows where to run the job: async (quickfix window), term, etc.

:AsyncRun -mode term make

This will open a terminal window and run the command there. It's very useful, but one thing I wish is the output of the command can be captured and sent to the quickfix window when the job finishes, and/or streamed to the quickfix window (optionally).

Such a feature would very useful to navigate and browse the command output (which will be lost when the terminal closes), like compilation error and diagnostics messages, etc.

skywind3000 commented 1 year ago

It is possible:

:AsyncRun -mode=term -pos=TAB -post=caddf\ ~/.error.txt|copen   ls | tee ~/.error.txt

If you are using asynctasks.vim:

You can define a new task:

[make-tee]
command=ls | tee ~/.error.txt
notify=:caddf ~/.error.txt | copen
output=terminal
pos=TAB

then:

:AsyncTask make-tee
wookayin commented 1 year ago

That's quite ugly -- but quite nice workaround. I think it would be quite non-trivial to stream the output from the terminal (but technically possible, see https://github.com/tpope/vim-dispatch), but first-class and seamless API would be good to have (so one can switch between different modes easily).

skywind3000 commented 1 year ago

try this: https://github.com/skywind3000/asyncrun.vim/releases/tag/2.10.8

wookayin commented 1 year ago
:AsyncRun -mode=term -pos=TAB -program=capture  ls -la

Why does it print some verbose messages like the following?

(1 of 1): [ls]
(1 of 29): [ls]
Press ENTER or type command to continue