Add function for wrapping prefixed keymap groups

This commit is contained in:
ViViDboarder 2022-01-10 10:47:51 -08:00
parent 6d2acddc56
commit cf97331465
2 changed files with 19 additions and 0 deletions

View File

@ -65,6 +65,12 @@ local function default_attach(client, bufnr)
-- Mappings
-- TODO: Maybe prefix all of these for easier discovery
local opts = { noremap = true, silent = true }
local lsp_keymap = utils.keymap_group("n", "<leader>l", opts, bufnr)
lsp_keymap("h", "<cmd>lua vim.lsp.buf.hover()<CR>")
lsp_keymap("r", "<cmd>lua vim.lsp.buf.rename()<CR>")
lsp_keymap("e", "<cmd>lua vim.lsp.diagnostics.show_line_diagnostics()<CR>")
buf_set_keymap("n", "gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>", opts)
buf_set_keymap("n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", opts)
buf_set_keymap("n", "K", "<Cmd>lua vim.lsp.buf.hover()<CR>", opts)

View File

@ -200,4 +200,17 @@ function M.map_version_rule(rules)
return latest_value
end
function M.keymap_group(mode, prefix, opts, bufnr)
local map_fn = vim.api.nvim_set_keymap
if bufnr ~= nil then
map_fn = function(...)
return vim.api.nvim_buf_set_keymap(bufnr, ...)
end
end
return function(keys, rhs, new_opts)
map_fn(mode, prefix .. keys, rhs, new_opts or opts)
end
end
return M