1

I run my make commands asynchronously in vim with the asyncrun plugin.

I use this code in my .vimrc to open the quickfix window automatically everytime I run an asynchronous make command in order to see the output.

augroup vimrc
    autocmd QuickFixCmdPost * botright copen 8
augroup END
nnoremap <leader>m :AsyncRun -cwd=<root> make<CR>

I usually don't want to jump into the quickfix window, but only open it and see the output. I couldn't find a way how to achieve this.

1

I had the same thinking for a solution as the other answer here has (wincmd p). But I found it was not 100% reliable depending on what quickfix command type is being used.

If you have issues with that solution you might have some better luck with a solution that uses explicit window/buffer references. An easy approach is to save the current buffer name in a global variable and jump to its "buffer window number" after the QF command runs...

autocmd QuickFixCmdPre * let g:mybufname=bufname('%')
autocmd QuickFixCmdPost * botright copen 8 | exec bufwinnr(g:mybufname) . 'wincmd w'
  • @Jonas Cool. You're welcome. – B Layer Jul 21 '18 at 3:53
2

Actually asyncrun has that feature. According to the document:

AsyncRun displays its output in quickfix window, so if you don't use :copen {height} to open quickfix window, you won't see any output. For convenience there is an option g:asyncrun_open for you.

So you just put this code :let g:asyncrun_open = 8 in your .vimrc.

When you press <leader>m, asyncrun will open quickfix window automatically. I've tested that it will only open the quickfix window but still focus you r current window. Enjoy~

1

Running wincmd p after the copen should work; you jump to the quickfix window and then right back to the window you were in e.g.

autocmd QuickFixCmdPost * botright copen 8 | wincmd p

see :h wincmd, :h CTRL-W_p

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.