Quickfix Location List linter window stays open

198 Views Asked by At

I love the linters and the quickfix window, but on occasion I don't want to fix anything and simply want to exit the file. The current issue is that when I close the file, the quickfix window stays open. I know I can use :qa to exit both at the same time, but I often forget to.

I spent a few hours trying to figure out how to close the quickfix buffer if it was the only open window/buffer left, but had no luck.

Anyone else know how to handle this better?

2

There are 2 best solutions below

0
romainl On BEST ANSWER

That feature is part of my vim-qf plugin but you don't really need a full-fledged plugin for such a mundane task. Actually, there have been many snippets floating around the internet for many years. Here is one:

augroup MyGroup
    autocmd!
    if exists('##QuitPre')
        autocmd QuitPre * if &filetype != 'qf' | silent! lclose | endif
    endif
augroup END

Basically, it closes the current quickfix/location window if it is the last remaining window in the current tab page.

Reference:

:help :augroup
:help :autocmd
:help exists()
:help QuitPre
2
phd On
if version >= 700
" automatically close quickfix if it's the only window left
autocmd WinEnter * if winnr('$') == 1 && &buftype == "quickfix" | quit | endif
endif