qlean is a Neovim plugin that prevents the “only auxiliary UI windows remain”
problem when you close your last keep-designated window.
It runs only when there is exactly one keep-designated window.
- On
:q, if only one keep-designated window remains and the current window is keep-designated- It closes non-keep-designated windows (help/quickfix/tree, etc.)
- It still performs cleanup even if buffers are modified
- Whether
:qsucceeds is left to Neovim
- Whether
qlean does not force quitting.
{
"kyoh86/qlean.nvim",
}(For other plugin managers, use the same placement.)
No extra commands are needed. qlean hooks into QuitPre.
If you don't set anything, buftype == '' is treated as keep.
local rule = require("qlean.rule")
require("qlean").setup({})- Normal files (
buftype == '') are treated as keep-designated buffers - Windows showing other buffers (help/quickfix/tree, etc.) are closed before quit
keep is a function that decides whether a buffer should be kept at quit time.
keep(ctx) == true- Treated as a keep-designated buffer and not auto-closed
keep(ctx) == false- Not a keep-designated buffer, so the window showing that buffer is closed
keep = rule.any(
rule.buftype(""),
rule.buftype("terminal")
)keep = rule.any(
rule.buftype(""),
rule.filetype("gitcommit", "gitrebase")
)keep = rule.all(
rule.buftype(""),
rule.not(rule.bufname("^neo%-tree://"))
)keep = function(ctx)
-- ctx includes bufnr / buftype / filetype / bufname, etc.
-- See the lua/qlean/type.lua for details.
return ctx.bo.buftype == "" and ctx.bufname:match("/keep/") ~= nil
endqlean.rule provides utilities to build predicates for keep.
rule.all(p1, p2, ...)
rule.any(p1, p2, ...)
rule.not(p)rule.buftype(value, ...)
rule.filetype(value, ...)
rule.bufname(pattern)
rule.buflisted(bool)
rule.bufhidden(value, ...)
rule.modified(bool)
rule.modifiable(bool)
rule.bvar(key, value?)x can be a string. Pass multiple strings as varargs.
Inspired by kawarimidoll's article. Thank you.
- Does not affect
:q!/:qa! - Does not automate saving or discarding buffers