Push a bunch of mappings on some event, then pop them when you're done. Original mappings are preserved and restored on pop.
- Neovim >= 0.7
{
"luismede/stackmap.nvim",
}use { "luismede/stackmap.nvim" }Push the mappings for a particular mode under the name name.
name(string): identifier for this group of mappings, used later to pop.mode(string): a Neovim mode short name, e.g."n","i","v".mappings(table): key-value pairs of{ lhs = rhs, ... }. Anylhsthat already has a mapping is saved and restored whenpopis called.
require("stackmap").push("example", "n", {
["<Space>st"] = "echo 'Wow! this is awesome!'",
})Pop the name mappings. Restores the original mappings from before the
corresponding stackmap.push() call, or deletes the mapping if none existed.
require("stackmap").pop("example")A common use case is transient mappings, e.g. while a split window or a floating UI is open:
local stackmap = require("stackmap")
-- Open a window and push transient mappings
stackmap.push("my-window", "n", {
["q"] = function() require("my-window").close() end,
["<CR>"] = function() require("my-window").confirm() end,
})
-- ...later, when the window closes
stackmap.pop("my-window")MIT