Search code examples
vimpython-mode

Quickfix Location List linter window stays open


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?


Solution

  • 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