autocommand: Fix unmap function to check if the keymap exists before deleting

This commit is contained in:
Fabrice Mouhartem 2023-12-25 10:11:44 +01:00
parent faa55e3664
commit 432fabeed0

View File

@ -1,5 +1,12 @@
local markdown = vim.api.nvim_create_augroup("markdown", { clear = true }) 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 -- Recognize .md as pandoc
vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, { vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
pattern = {"*.md", }, pattern = {"*.md", },
@ -34,8 +41,8 @@ vim.api.nvim_create_autocmd({"OptionSet"}, {
vim.keymap.set("n", "<Leader>i", "mz[s1z=`z", {noremap = true, silent = true}) vim.keymap.set("n", "<Leader>i", "mz[s1z=`z", {noremap = true, silent = true})
vim.keymap.set("n", "à", "]s", {noremap = true, silent = true}) vim.keymap.set("n", "à", "]s", {noremap = true, silent = true})
else else
vim.keymap.del("n", "<Leader>i") keyunmap("n", "<Leader>i")
vim.keymap.del("n", "à") keyunmap("n", "à")
end end
end end
}) })