From 1dcf6c6067b8da61b18982f2bae8d5f10bacd7d3 Mon Sep 17 00:00:00 2001 From: Bobby Bingham Date: Sat, 2 Jul 2022 15:23:01 -0500 Subject: nvim: tweak lsp keys, add command aliases --- nvim/.config/nvim/lua/lsp_config.lua | 49 ++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 19 deletions(-) (limited to 'nvim') diff --git a/nvim/.config/nvim/lua/lsp_config.lua b/nvim/.config/nvim/lua/lsp_config.lua index 66ced3d..63a51d8 100644 --- a/nvim/.config/nvim/lua/lsp_config.lua +++ b/nvim/.config/nvim/lua/lsp_config.lua @@ -13,32 +13,43 @@ local buf_map = function(bufnr, mode, lhs, rhs, opts) }) end -map('n', 'e', 'lua vim.diagnostic.open_float()') -map('n', '[d', 'lua vim.diagnostic.goto_prev()') -map('n', ']d', 'lua vim.diagnostic.goto_next()') -map('n', 'q', 'lua vim.diagnostic.setloclist()') - -- 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) + vim.cmd("command! LspDef lua vim.lsp.buf.definition()") + vim.cmd("command! LspDeclaration lua vim.lsp.buf.declaration()") + vim.cmd("command! LspFormatting lua vim.lsp.buf.formatting()") + vim.cmd("command! LspCodeAction lua vim.lsp.buf.code_action()") + vim.cmd("command! LspHover lua vim.lsp.buf.hover()") + vim.cmd("command! LspRename lua vim.lsp.buf.rename()") + vim.cmd("command! LspRefs lua vim.lsp.buf.references()") + vim.cmd("command! LspTypeDef lua vim.lsp.buf.type_definition()") + vim.cmd("command! LspImplementation lua vim.lsp.buf.implementation()") + vim.cmd("command! LspDiagPrev lua vim.diagnostic.goto_prev()") + vim.cmd("command! LspDiagNext lua vim.diagnostic.goto_next()") + vim.cmd("command! LspDiagLine lua vim.diagnostic.open_float()") + vim.cmd("command! LspSignatureHelp lua vim.lsp.buf.signature_help()") + -- Enable completion triggered by vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') -- Mappings. - -- See `:help vim.lsp.*` for documentation on any of the below functions - buf_map(bufnr, 'n', 'gD', 'lua vim.lsp.buf.declaration()') - buf_map(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()') - buf_map(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()') - buf_map(bufnr, 'n', 'gi', 'lua vim.lsp.buf.implementation()') - buf_map(bufnr, 'n', '', 'lua vim.lsp.buf.signature_help()') - buf_map(bufnr, 'n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()') - buf_map(bufnr, 'n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()') - buf_map(bufnr, 'n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))') - buf_map(bufnr, 'n', 'D', 'lua vim.lsp.buf.type_definition()') - buf_map(bufnr, 'n', 'rn', 'lua vim.lsp.buf.rename()') - buf_map(bufnr, 'n', 'ca', 'lua vim.lsp.buf.code_action()') - buf_map(bufnr, 'n', 'gr', 'lua vim.lsp.buf.references()') - buf_map(bufnr, 'n', 'f', 'lua vim.lsp.buf.formatting()') + buf_map(bufnr, 'n', 'gD', ':LspDeclaration') + buf_map(bufnr, 'n', 'gd', ':LspDef') + buf_map(bufnr, 'n', 'gy', ':LspTypeDef') + buf_map(bufnr, 'n', 'gi', ':LspImplementation') + buf_map(bufnr, 'n', 'gr', ':LspRefs') + buf_map(bufnr, 'n', 'K', ':LspHover') + buf_map(bufnr, 'n', '[d', ':LspDiagPrev') + buf_map(bufnr, 'n', ']d', ':LspDiagNext') + buf_map(bufnr, 'n', 'd', ':LspDiagLine') + buf_map(bufnr, 'n', '', ':LspSignatureHelp') + buf_map(bufnr, 'n', 'wa', ':lua vim.lsp.buf.add_workspace_folder()') + buf_map(bufnr, 'n', 'wr', ':lua vim.lsp.buf.remove_workspace_folder()') + buf_map(bufnr, 'n', 'wl', ':lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))') + buf_map(bufnr, 'n', 'rn', ':LspRename') + buf_map(bufnr, 'n', 'ca', ':LspCodeAction') + buf_map(bufnr, 'n', 'f', ':LspFormatting') end -- Use a loop to conveniently call 'setup' on multiple servers and -- cgit v1.2.3