检测VIM中是否存在quickfix缓冲区

Mur*_*dle 6 vim

简单的问题(我希望).这让我疯了.我正在尝试在我的vimrc中创建一个简单的脚本来映射:

<Leader>e

打开quickfix窗口.如果当前打开,我还希望关键组合关闭quickfix窗口.问题是,bufexists命令似乎跳过了quickfix缓冲区.你能否就如何检测是否已经打开quickfix窗口给我一些建议?

ros*_*dia 7

:cwindow命令可能是您正在寻找的.从帮助:

                            *: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.
Run Code Online (Sandbox Code Playgroud)

但是,如果您想关闭quickfix窗口,即使仍有错误,请查看此Vim提示,它提供以下代码段:

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
Run Code Online (Sandbox Code Playgroud)