How can I close vim if the only window left open is a quickfix window?
I try to add this
autocmd bufenter * if (winnr("$") == 1 && exists("b:loaded_flake8_ftplugin") && b:loaded_flake8_ftplugin == "primary") | q | endif
but it not work
I wanted something close to what you wanted - on :w I wanted a quick fix, but on :wq I did not. Here's my hack for that in case it helps:
autocmd BufWritePost *.py call Flake8()
function NoShow()
let g:flake8_show_quickfix=0
wq
endfunction
autocmd FileType python cmap wq call NoShow()
Here is what I am using right now:
autocmd FileType python cnoreabbrev <expr> q winnr("$") > 1 && getcmdtype() == ":" && getcmdline() == 'q' ? 'ccl <BAR> q' : 'q'
It will automatically close the quick fix window if there is one.
Combining with @khadiwala answer is enough for my usage.
@khadiwala @garywahaha cool,
but I test @khadiwala way, :q and :x not work.
and @garywahaha way :wq and x not work
@axiaoxin In that case I think you may try
function NoShow()
let g:flake8_show_quickfix=0
wq
endfunction
autocmd FileType python cnoreabbrev <expr> wq getcmdtype() == ":" && getcmdline() == 'wq' ? 'call NoShow()' : 'wq'
autocmd FileType python cnoreabbrev <expr> q winnr("$") > 1 && getcmdtype() == ":" && getcmdline() == 'q' ? 'ccl <BAR> q' : 'q'
autocmd FileType python cnoreabbrev <expr> x winnr("$") > 1 && getcmdtype() == ":" && getcmdline() == 'x' ? 'ccl <BAR> x' : 'x'
A more generic solution not specific for Python nor Flake8:
" Close vim if the only window left is quickfix
aug QFClose
au!
au WinEnter * if winnr('$') == 1 && &buftype == "quickfix"|q|endif
aug END