fix(api): add lhs option for keymap deletion

This commit is contained in:
Barrett Ruth
2026-07-25 10:26:01 -07:00
parent 1facf1e081
commit 22d44ef875
13 changed files with 120 additions and 31 deletions

View File

@@ -119,8 +119,11 @@ end
---
--- Remove a mapping from the given buffer. `0` for current.
--- @field buf? integer
--- When true, only match {lhs}, not {rhs}.
--- @field lhs? boolean
--- Removes a mapping, or removes each (mode, lhs) pair if `lhs` is a list.
---
--- Examples:
---
--- ```lua
@@ -152,12 +155,14 @@ function keymap.del(modes, lhs, opts)
buf = opts.buffer == true and 0 or opts.buffer --[[@as integer?]]
end
local api_opts = { lhs = opts.lhs }
for _, m in ipairs(modes) do
for _, l in ipairs(lhs) do
if buf then
vim.api.nvim_buf_del_keymap(buf, m, l)
vim.api.nvim_buf_del_keymap(buf, m, l, api_opts)
else
vim.api.nvim_del_keymap(m, l)
vim.api.nvim_del_keymap(m, l, api_opts)
end
end
end