diff --git a/README.md b/README.md index a851ea1..e711d5a 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,7 @@ Here's the default mapping object for reference: ``` Want to not set a keybind for a given action? Set the bound value to `'NONE'` and it will skip being set. +Keybinds can be set to either individual strings or arrays of strings, so for example `window_mappings.cursor_down` above could be mapped to `{ 'j', 's' }`. Check the mentioned help screen to see current keybinds and their use: diff --git a/lua/spelunk/config.lua b/lua/spelunk/config.lua index 5270d58..d4040ef 100644 --- a/lua/spelunk/config.lua +++ b/lua/spelunk/config.lua @@ -63,27 +63,53 @@ M.get_default = function(key) return default_config[key] end ----@param key string +---@param key string | string[] ---@param cmd string | function ---@param description string M.set_keymap = function(key, cmd, description) - if key == skipkey then - return + ---@param val string + local apply = function(val) + if val == skipkey then + return + end + vim.keymap.set('n', val, cmd, + { desc = description, noremap = true, silent = true }) + end + if type(key) == 'string' then + apply(key) + elseif type(key) == 'table' then + for _, k in pairs(key) do + apply(k) + end + else + error('[spelunk.nvim] config.set_keymap passed unsupported type: ' .. type(key)) end - vim.keymap.set('n', key, cmd, - { desc = description, noremap = true, silent = true }) end ---@param bufnr integer M.set_buf_keymap = function(bufnr) - ---@param key string + ---@param val string + ---@param f string + ---@param desc string + local apply = function(val, f, desc) + if val == skipkey then + return + end + vim.api.nvim_buf_set_keymap(bufnr, 'n', val, f, { noremap = true, silent = true, desc = desc }) + end + ---@param key string | string[] ---@param func string ---@param description string return function(key, func, description) - if key == skipkey then - return + if type(key) == 'string' then + apply(key, func, description) + elseif type(key) == 'table' then + for _, k in pairs(key) do + apply(k, func, description) + end + else + error('[spelunk.nvim] config.set_buf_keymap passed unsupported type: ' .. type(key)) end - vim.api.nvim_buf_set_keymap(bufnr, 'n', key, func, { noremap = true, silent = true, desc = description }) end end