From cf973314650618fe7bc2ff6fab62ce41e62aca62 Mon Sep 17 00:00:00 2001 From: ViViDboarder Date: Mon, 10 Jan 2022 10:47:51 -0800 Subject: [PATCH] Add function for wrapping prefixed keymap groups --- neovim/lua/plugins/lsp.lua | 6 ++++++ neovim/lua/utils.lua | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/neovim/lua/plugins/lsp.lua b/neovim/lua/plugins/lsp.lua index a7d1de5..2224799 100644 --- a/neovim/lua/plugins/lsp.lua +++ b/neovim/lua/plugins/lsp.lua @@ -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", "l", opts, bufnr) + lsp_keymap("h", "lua vim.lsp.buf.hover()") + lsp_keymap("r", "lua vim.lsp.buf.rename()") + lsp_keymap("e", "lua vim.lsp.diagnostics.show_line_diagnostics()") + buf_set_keymap("n", "gD", "lua vim.lsp.buf.declaration()", opts) buf_set_keymap("n", "gd", "lua vim.lsp.buf.definition()", opts) buf_set_keymap("n", "K", "lua vim.lsp.buf.hover()", opts) diff --git a/neovim/lua/utils.lua b/neovim/lua/utils.lua index d043fd3..814c933 100644 --- a/neovim/lua/utils.lua +++ b/neovim/lua/utils.lua @@ -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