Search code examples
vimvim-quickfix

Execute vim pipe only when system() reports an error?


I have the following vim auto command:

autocmd BufWritePost *.go :cex system('revive '..expand('%:p')) | copen

It executes a binary called revive, passing it the current file path, and then opens up the quickfix window with the results from the revive binary.

But if the revive binary returns empty I'd prefer not to have the quickfix window opened.

Wondering if there's a better way to handle this? Is there a way to check for an error status or checking the length of the quickfix results before opening?

Thanks!


Solution

  • @romainl solved this for me by commenting about :cwindow.

    The use of :cwindow prevents the quickfix window opening unless there are error items in the list.

    Thanks Romainl