Simple question (I hope). It's driving me nuts. I'm trying to create a simple script in my vimrc to map:
<Leader>e
to open the quickfix window. I also want that key combo to close the quickfix window if it is currently open. The problem is, the bufexists command seems to skip over the quickfix buffers. Can you please give me some advice on how to detect if there is a quickfix window already open?
The :cwindow
command might be what you're looking for. From the help:
*:cw* *:cwindow*
:cw[indow] [height] Open the quickfix window when there are recognized
errors. If the window is already open and there are
no recognized errors, close the window.
However, if you want to close the quickfix window even if there are still errors, then check out this Vim Tip, which provides the following snippet:
command -bang -nargs=? QFix call QFixToggle(<bang>0)
function! QFixToggle(forced)
if exists("g:qfix_win") && a:forced == 0
cclose
unlet g:qfix_win
else
copen 10
let g:qfix_win = bufnr("$")
endif
endfunction
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