LunarVim/lua/utils/keymap.lua
Luc Sinet 6d14d7b5da
[Refactor] Adopt which key mapping style (#1210)
* Refactor keymappings to match which-key style

* Update confif example + remove redundant way of registering mappings
2021-08-02 11:19:44 -04:00

31 lines
836 B
Lua

local M = {}
local mode_adapters = {
insert_mode = "i",
normal_mode = "n",
term_mode = "t",
visual_mode = "v",
visual_block_mode = "x",
}
-- Load key mappings for a given mode
-- @param mode The keymap mode, can be one of the keys of mode_adapters
-- @param keymaps The list of key mappings
-- @param opts The mapping options
M.load_mode = function(mode, keymaps, opts)
mode = mode_adapters[mode] and mode_adapters[mode] or mode
for key, mapping in pairs(keymaps) do
vim.api.nvim_set_keymap(mode, key, mapping[1], opts)
end
end
-- Load key mappings for all provided modes
-- @param keymaps A list of key mappings for each mode
-- @param opts The mapping options for each mode
M.load = function(keymaps, opts)
for mode, mapping in pairs(keymaps) do
M.load_mode(mode, mapping, opts[mode])
end
end
return M