From 0b4a493d60da6381678bd6f325c763d9fa0c8ae1 Mon Sep 17 00:00:00 2001 From: guanghechen <42513619+guanghechen@users.noreply.github.com> Date: Wed, 26 Mar 2025 21:58:03 +0800 Subject: [PATCH] improve: support to customize the keymaps for cancelling the editing (#1730) * improve: support to customize the keymaps for cancelling the editing * docs: update README --- README.md | 4 ++++ lua/avante/config.lua | 4 ++++ lua/avante/ui/prompt_input.lua | 8 ++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 45d26fc..b2e888d 100644 --- a/README.md +++ b/README.md @@ -366,6 +366,10 @@ _See [config.lua#L9](./lua/avante/config.lua) for the full config_ normal = "", insert = "", }, + cancel = { + normal = { "", "", "q" }, + insert = { "" }, + }, sidebar = { apply_all = "A", apply_cursor = "a", diff --git a/lua/avante/config.lua b/lua/avante/config.lua index 48d8663..a9c2bc3 100644 --- a/lua/avante/config.lua +++ b/lua/avante/config.lua @@ -383,6 +383,10 @@ M._defaults = { normal = "", insert = "", }, + cancel = { + normal = { "", "", "q" }, + insert = { "" }, + }, -- NOTE: The following will be safely set by avante.nvim ask = "aa", edit = "ae", diff --git a/lua/avante/ui/prompt_input.lua b/lua/avante/ui/prompt_input.lua index 54f3a9b..c87de0e 100644 --- a/lua/avante/ui/prompt_input.lua +++ b/lua/avante/ui/prompt_input.lua @@ -268,8 +268,12 @@ function PromptInput:setup_keymaps() { buffer = bufnr, noremap = true, silent = true } ) - vim.keymap.set("n", "", function() self:cancel() end, { buffer = bufnr }) - vim.keymap.set("n", "q", function() self:cancel() end, { buffer = bufnr }) + for _, key in ipairs(Config.mappings.cancel.normal) do + vim.keymap.set("n", key, function() self:cancel() end, { buffer = bufnr }) + end + for _, key in ipairs(Config.mappings.cancel.insert) do + vim.keymap.set("i", key, function() self:cancel() end, { buffer = bufnr }) + end end function PromptInput:setup_autocmds()