diff options
author | Abouzar Parvan <[email protected]> | 2022-05-03 19:01:53 +0430 |
---|---|---|
committer | GitHub <[email protected]> | 2022-05-03 19:01:53 +0430 |
commit | e1d32ca42ee6fdef8c724e3f391e548895f0bdcf (patch) | |
tree | 3dd52f16dc043e7e2db92b6b98f0ed58b8689898 | |
parent | 5566076ebb539a7d72dd64af257413fd4dde6157 (diff) |
feat(quit): make sure to ask before discarding changes (#2554)
-rw-r--r-- | lua/lvim/core/which-key.lua | 2 | ||||
-rw-r--r-- | lua/lvim/utils/functions.lua | 19 |
2 files changed, 20 insertions, 1 deletions
diff --git a/lua/lvim/core/which-key.lua b/lua/lvim/core/which-key.lua index 3c3cc66b..be4487f3 100644 --- a/lua/lvim/core/which-key.lua +++ b/lua/lvim/core/which-key.lua @@ -82,7 +82,7 @@ M.config = function() mappings = { [";"] = { "<cmd>Alpha<CR>", "Dashboard" }, ["w"] = { "<cmd>w!<CR>", "Save" }, - ["q"] = { "<cmd>q!<CR>", "Quit" }, + ["q"] = { "<cmd>lua require('lvim.utils.functions').smart_quit()<CR>", "Quit" }, ["/"] = { "<cmd>lua require('Comment.api').toggle_current_linewise()<CR>", "Comment" }, ["c"] = { "<cmd>BufferKill<CR>", "Close Buffer" }, ["f"] = { require("lvim.core.telescope.custom-finders").find_project_files, "Find File" }, 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 |