From 432fabeed010fc51b9994ac83f9322a14e76da36 Mon Sep 17 00:00:00 2001 From: Fabrice Mouhartem Date: Mon, 25 Dec 2023 10:11:44 +0100 Subject: [PATCH] autocommand: Fix unmap function to check if the keymap exists before deleting --- lua/autocommands.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lua/autocommands.lua b/lua/autocommands.lua index c4aaba1..00c3e99 100644 --- a/lua/autocommands.lua +++ b/lua/autocommands.lua @@ -1,5 +1,12 @@ local markdown = vim.api.nvim_create_augroup("markdown", { clear = true }) +local keyunmap = function(mode, binding) + print(vim.inspect(vim.fn.maparg(binding, mode))) + if vim.fn.maparg(binding, mode) ~= "" then + vim.keymap.del(mode, binding) + end +end + -- Recognize .md as pandoc vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, { pattern = {"*.md", }, @@ -34,8 +41,8 @@ vim.api.nvim_create_autocmd({"OptionSet"}, { vim.keymap.set("n", "i", "mz[s1z=`z", {noremap = true, silent = true}) vim.keymap.set("n", "à", "]s", {noremap = true, silent = true}) else - vim.keymap.del("n", "i") - vim.keymap.del("n", "à") + keyunmap("n", "i") + keyunmap("n", "à") end end })