This plugin will give you a confirmation message when you close the last window. It prevents Neovim from closing unexpectedly.
{
"yutkat/confirm-quit.nvim",
event = "CmdlineEnter",
opts = {},
}
use {
"yutkat/confirm-quit.nvim",
event = "CmdlineEnter",
config = function() require "confirm-quit".setup() end,
}
{
overwrite_q_command = true, -- Replaces :q and :qa with :ConfirmQuit and :ConfirmQuitAll
}
You do not need to use those commands directly. :q
and :qa
are aliases to :ConfirmQuit
and :ConfirmQuitAll
if you didn't change the default config.
I also recommend you set vim.opt.confirm = true
to get prompted if you want to save all the unsaved changes.
ConfirmQuit " Same as :q, unless it's the last window, in which case it prompts you before taking any action.
ConfirmQuitAll " Similar to :ConfirmQuit. Will always prompt you to quit
ConfirmQuit! " An alias to :q!
ConfirmQuitAll! " An alias to :qa!
require "confirm-quit".confirm_quit() -- :ConfirmQuit
require "confirm-quit".confirm_quit_all() -- :ConfirmQuitAll
require "confirm-quit".confirm_quit { bang = true } -- ConfirmQuit!
require "confirm-quit".confirm_quit_all { bang = true } -- ConfirmQuitAll!
Here's an example of how you'd set up keymaps:
vim.keymap.set("n", "<leader>q", require "confirm-quit".confirm_quit)
vim.keymap.set("n", "<leader>Q", require "confirm-quit".confirm_quit_all)