Skip to content

Commit 95faa49

Browse files
theopnemilandcgi
authored andcommitted
Change LSP Keybindings to Match the Default gr Bindings Introduced in Neovim 0.11 (nvim-lua#1427)
* refactor: change LSP keybindings to the default gr bindings introduced in 0.11 * refactor: modify existing LSP functions to follow convention
1 parent 91f4a1e commit 95faa49

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

init.lua

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,7 @@ require('lazy').setup({
341341

342342
-- Document existing key chains
343343
spec = {
344-
{ '<leader>c', group = '[C]ode', mode = { 'n', 'x' } },
345-
{ '<leader>d', group = '[D]ocument' },
346-
{ '<leader>r', group = '[R]ename' },
347344
{ '<leader>s', group = '[S]earch' },
348-
{ '<leader>w', group = '[W]orkspace' },
349345
{ '<leader>t', group = '[T]oggle' },
350346
{ '<leader>h', group = 'Git [H]unk', mode = { 'n', 'v' } },
351347
},
@@ -537,42 +533,42 @@ require('lazy').setup({
537533
vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
538534
end
539535

540-
-- Jump to the definition of the word under your cursor.
541-
-- This is where a variable was first declared, or where a function is defined, etc.
542-
-- To jump back, press <C-t>.
543-
map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
536+
-- Rename the variable under your cursor.
537+
-- Most Language Servers support renaming across files, etc.
538+
map('grn', vim.lsp.buf.rename, '[R]e[n]ame')
539+
540+
-- Execute a code action, usually your cursor needs to be on top of an error
541+
-- or a suggestion from your LSP for this to activate.
542+
map('gra', vim.lsp.buf.code_action, '[G]oto Code [A]ction', { 'n', 'x' })
544543

545544
-- Find references for the word under your cursor.
546-
map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
545+
map('grr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
547546

548547
-- Jump to the implementation of the word under your cursor.
549548
-- Useful when your language has ways of declaring types without an actual implementation.
550-
map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
549+
map('gri', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
551550

552-
-- Jump to the type of the word under your cursor.
553-
-- Useful when you're not sure what type a variable is and you want to see
554-
-- the definition of its *type*, not where it was *defined*.
555-
map('<leader>D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition')
551+
-- Jump to the definition of the word under your cursor.
552+
-- This is where a variable was first declared, or where a function is defined, etc.
553+
-- To jump back, press <C-t>.
554+
map('grd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
555+
556+
-- WARN: This is not Goto Definition, this is Goto Declaration.
557+
-- For example, in C this would take you to the header.
558+
map('grD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
556559

557560
-- Fuzzy find all the symbols in your current document.
558561
-- Symbols are things like variables, functions, types, etc.
559-
map('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
562+
map('gO', require('telescope.builtin').lsp_document_symbols, 'Open Document Symbols')
560563

561564
-- Fuzzy find all the symbols in your current workspace.
562565
-- Similar to document symbols, except searches over your entire project.
563-
map('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
564-
565-
-- Rename the variable under your cursor.
566-
-- Most Language Servers support renaming across files, etc.
567-
map('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
568-
569-
-- Execute a code action, usually your cursor needs to be on top of an error
570-
-- or a suggestion from your LSP for this to activate.
571-
map('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction', { 'n', 'x' })
566+
map('gW', require('telescope.builtin').lsp_dynamic_workspace_symbols, 'Open Workspace Symbols')
572567

573-
-- WARN: This is not Goto Definition, this is Goto Declaration.
574-
-- For example, in C this would take you to the header.
575-
map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
568+
-- Jump to the type of the word under your cursor.
569+
-- Useful when you're not sure what type a variable is and you want to see
570+
-- the definition of its *type*, not where it was *defined*.
571+
map('grt', require('telescope.builtin').lsp_type_definitions, '[G]oto [T]ype Definition')
576572

577573
-- This function resolves a difference between neovim nightly (version 0.11) and stable (version 0.10)
578574
---@param client vim.lsp.Client

0 commit comments

Comments
 (0)