local vim = vim local noremap = function(type, rhs, lhs, bufopts, desc) bufopts.desc = desc vim.keymap.set(type, rhs, lhs, bufopts) end local nnoremap = function(rhs, lhs, bufopts, desc) noremap("n", rhs, lhs, bufopts, desc) end local vnoremap = function(rhs, lhs, bufopts, desc) noremap("v", rhs, lhs, bufopts, desc) end local bufopts = { noremap = true, silent = true } nnoremap("gD", vim.lsp.buf.declaration, bufopts, "Go to declaration") nnoremap("gd", vim.lsp.buf.definition, bufopts, "Go to definition") nnoremap("gi", vim.lsp.buf.implementation, bufopts, "Go to implementation") nnoremap("td", vim.lsp.buf.type_definition, bufopts, "Go to type definition") nnoremap("gr", vim.lsp.buf.references, bufopts, "Go to references") nnoremap("rn", vim.lsp.buf.rename, bufopts, "Rename") nnoremap("ca", vim.lsp.buf.code_action, bufopts, "Code actions") vnoremap("ca", "lua vim.lsp.buf.range_code_action()", bufopts, "Code Actions")