Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting if quickfix buffer exists in VIM

Tags:

vim

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?

like image 324
Murphy Randle Avatar asked Nov 09 '11 06:11

Murphy Randle


1 Answers

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
like image 55
rossipedia Avatar answered Sep 19 '22 23:09

rossipedia