Here is another way to do this, possibly missing some gory details, but it works:
function! ToggleQuickFix() if exists("g:qwindow") lclose unlet g:qwindow else try lopen 10 let g:qwindow = 1 catch echo "No Errors found!" endtry endif endfunction nmap <script> <silent> <F2> :call ToggleQuickFix()<CR>
If there are no errors, the lopen function will not work, so I will try to catch it if it opens a window and creates a variable. then if he does not close it.
The most interesting thing is that this approach can be used for everything that you would like to switch.
source share