I'd like to run some $RANDOM_COMMAND
, and have the results opened in ("piped to") the quickfix window (:copen
/:cfile
). Is this possible, without having to define some commands in vimrc? (Hopefully in some "simple way", i.e. I'd like to be able to memorize this so I can run this on any new random box with vanilla vim that I'll have to login to.)
edit: initially didn't know how to express "simple way" more precisely, but now I know at least partially: I'd much prefer an answer of 1, max 2 lines.
edit2: tried something like below (from this and this):
:call setqflist(split(system('RANDOM_COMMAND'), '\n'))
:copen
but didn't seem to work anyway :/ (and mucho ugly too)
One way to do this:
:set makeprg=$RANDOM_COMMAND
:make
:copen
Or, execute the command and capture the output in a temporary file:
:! $RANDOM_COMMAND > out
:cfile out
:copen
In any way, the output must match with the 'errorformat'
setting, so that Vim can parse the file name and line numbers (if you need those; but otherwise, you could just use a scratch buffer as well the quickfix list).
To make this a oneliner, then somewhat shortened, you can:
:set mp=RANDOM_COMMAND | make | copen
Whitespaces in command must be escaped with backslash; also, the make
command can take arguments, which get expanded in place of a $*
; a more full-blown example thus:
:set mp=mycommand\ -d\ $PWD\ $* | make myarg | copen
Alternatively, similar thing can be done with :set grepprg
and :grep
, giving even shorter line:
:set gp=mycommand\ -d\ $PWD\ $* | gr myarg | copen
Hmh, found the simplest solution in the end, by reading through the regular vimdoc for quickfix window:
:cex system('$RANDOM_COMMAND') | copen
(the | copen
part is optional).
Still, Ingo Karkat's solution can have usability advantage, as on consecutive runs it's enough to run shorter :grep there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With