feat(actions): add close_float to close only floating oil windows

Problem: users who bind <Esc> to close oil in floating windows also
accidentally close oil in split or fullscreen windows. There is no
action that closes only a floating oil window and is a no-op otherwise.

Solution: add a close_float action that checks vim.w.is_oil_win (the
same window-local variable oil.close already uses to identify its own
floating windows) before delegating to oil.close.

Resolves: stevearc/oil.nvim#645
This commit is contained in:
Barrett Ruth 2026-02-20 20:24:06 -05:00
parent ce64ae18de
commit f6bcdda988
Signed by: barrett
GPG key ID: A6C96C9349D2FC81

View file

@ -179,6 +179,22 @@ M.close = {
},
}
M.close_float = {
desc = "Close oil if the window is floating, otherwise do nothing",
callback = function(opts)
if vim.w.is_oil_win then
opts = opts or {}
oil.close(opts)
end
end,
parameters = {
exit_if_last_buf = {
type = "boolean",
desc = "Exit vim if oil is closed as the last buffer",
},
},
}
---@param cmd string
---@param silent? boolean
local function cd(cmd, silent)