Skip to content

Commit d4c92f7

Browse files
theopnarkottke
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 fec99fe commit d4c92f7

1 file changed

Lines changed: 23 additions & 27 deletions

File tree

init.lua

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

345345
-- Document existing key chains
346346
spec = {
347-
{ '<leader>c', group = '[C]ode', mode = { 'n', 'x' } },
348-
{ '<leader>d', group = '[D]ocument' },
349-
{ '<leader>r', group = '[R]ename' },
350347
{ '<leader>s', group = '[S]earch' },
351-
{ '<leader>w', group = '[W]orkspace' },
352348
{ '<leader>t', group = '[T]oggle' },
353349
{ '<leader>h', group = 'Git [H]unk', mode = { 'n', 'v' } },
354350
},
@@ -540,42 +536,42 @@ require('lazy').setup({
540536
vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
541537
end
542538

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

548547
-- Find references for the word under your cursor.
549-
map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
548+
map('grr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
550549

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

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

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

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

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

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

0 commit comments

Comments
 (0)