2011-11-09 35 views
5

简单的问题(我希望)。 这让我疯狂。我试图建立在我的vimrc一个简单的脚本映射:检测VIM中是否存在quickfix缓冲区

<Leader>e

打开quickfix窗口。如果它当前打开,我也希望该组合键关闭quickfix窗口。 问题是,bufexists命令似乎跳过了quickfix缓冲区。 你可以给我一些建议如何检测是否有一个quickfix窗口已经打开?

回答

6

: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. 

不过,如果你想关闭,即使仍有错误quickfix窗口,然后检查this Vim Tip,它提供了下面的代码片段:

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 
+0

完美!非常感谢! – splodingsocks