From 5c93bb42bf1b022c25e187ee15cb88446466eeab Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Fri, 27 Oct 2023 19:30:16 +0800 Subject: [PATCH] nvim: refactor setting of keymaps --- nvim/lua/lsp-user-config.lua | 37 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/nvim/lua/lsp-user-config.lua b/nvim/lua/lsp-user-config.lua index dc9140e..1f57ffd 100644 --- a/nvim/lua/lsp-user-config.lua +++ b/nvim/lua/lsp-user-config.lua @@ -5,9 +5,6 @@ function setup() -- Use an on_attach function to only map the following keys -- after the language server attaches to the current buffer local on_attach = function(client, bufnr) - local function keymap_set(...) - vim.api.nvim_buf_set_keymap(bufnr, ...) - end local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end @@ -19,23 +16,23 @@ function setup() local opts = { noremap = true, silent = true } -- See `:help vim.lsp.*` for documentation on any of the below functions - keymap_set("n", "gD", "lua vim.lsp.buf.declaration()", opts) - keymap_set("n", "gd", "lua vim.lsp.buf.definition()", opts) - keymap_set("n", "K", "lua vim.lsp.buf.hover()", opts) - keymap_set("n", "gi", "lua vim.lsp.buf.implementation()", opts) - keymap_set("n", "", "lua vim.lsp.buf.signature_help()", opts) - keymap_set("n", "wa", "lua vim.lsp.buf.add_workspace_folder()", opts) - keymap_set("n", "wr", "lua vim.lsp.buf.remove_workspace_folder()", opts) - keymap_set("n", "wl", "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", opts) - keymap_set("n", "D", "lua vim.lsp.buf.type_definition()", opts) - keymap_set("n", "rn", "lua vim.lsp.buf.rename()", opts) - keymap_set("n", "ca", "lua vim.lsp.buf.code_action()", opts) - keymap_set("n", "gr", "lua vim.lsp.buf.references()", opts) - keymap_set("n", "e", "lua vim.lsp.diagnostic.show_line_diagnostics()", opts) - keymap_set("n", "[d", "lua vim.lsp.diagnostic.goto_prev()", opts) - keymap_set("n", "]d", "lua vim.lsp.diagnostic.goto_next()", opts) - keymap_set("n", "q", "lua vim.lsp.diagnostic.set_loclist()", opts) - keymap_set("n", "f", "lua vim.lsp.buf.formatting()", opts) + vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) + vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) + vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) + vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) + vim.keymap.set("n", "", vim.lsp.buf.signature_help, opts) + vim.keymap.set("n", "wa", vim.lsp.buf.add_workspace_folder, opts) + vim.keymap.set("n", "wr", vim.lsp.buf.remove_workspace_folder, opts) + vim.keymap.set("n", "wl", print(vim.inspect(vim.lsp.buf.list_workspace_folders, opts))) + vim.keymap.set("n", "D", vim.lsp.buf.type_definition, opts) + vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) + vim.keymap.set("n", "ca", vim.lsp.buf.code_action, opts) + vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) + vim.keymap.set("n", "e", vim.lsp.diagnostic.show_line_diagnostics, opts) + vim.keymap.set("n", "[d", vim.lsp.diagnostic.goto_prev, opts) + vim.keymap.set("n", "]d", vim.lsp.diagnostic.goto_next, opts) + vim.keymap.set("n", "q", vim.lsp.diagnostic.set_loclist, opts) + vim.keymap.set("n", "f", vim.lsp.buf.formatting, opts) end local capabilities = vim.lsp.protocol.make_client_capabilities()