diff --git a/lua/oil/init.lua b/lua/oil/init.lua index 72d5538a..39ee7537 100644 --- a/lua/oil/init.lua +++ b/lua/oil/init.lua @@ -386,6 +386,13 @@ end ---@param opts? oil.CloseOpts M.close = function(opts) opts = opts or {} + local mode = vim.api.nvim_get_mode().mode + -- If we're in operator pending or visual modes, we should cancel that operation and return + if mode == "no" or mode == "v" or mode == "V" then + -- Trigger to cancel the operation + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("", true, true, true), "n", false) + return + end -- If we're in a floating oil window, close it and try to restore focus to the original window if vim.w.is_oil_win then local original_winid = vim.w.oil_original_win