From e1d32ca42ee6fdef8c724e3f391e548895f0bdcf Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Tue, 3 May 2022 19:01:53 +0430 Subject: feat(quit): make sure to ask before discarding changes (#2554) --- lua/lvim/utils/functions.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 lua/lvim/utils/functions.lua (limited to 'lua/lvim/utils/functions.lua') diff --git a/lua/lvim/utils/functions.lua b/lua/lvim/utils/functions.lua new file mode 100644 index 00000000..de46bc8a --- /dev/null +++ b/lua/lvim/utils/functions.lua @@ -0,0 +1,19 @@ +local M = {} + +function M.smart_quit() + local bufnr = vim.api.nvim_get_current_buf() + local modified = vim.api.nvim_buf_get_option(bufnr, "modified") + if modified then + vim.ui.input({ + prompt = "You have unsaved changes. Quit anyway? (y/n) ", + }, function(input) + if input == "y" then + vim.cmd "q!" + end + end) + else + vim.cmd "q!" + end +end + +return M -- cgit v1.2.3