Skip to content

Commit 1a5787b

Browse files
authored
Change LSP Keybindings to Match the Default gr Bindings Introduced in Neovim 0.11 (#1427)
* refactor: change LSP keybindings to the default gr bindings introduced in 0.11 * refactor: modify existing LSP functions to follow convention
1 parent 8a5a52f commit 1a5787b

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

init.lua

+23-27
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,7 @@ require('lazy').setup({
336336

337337
-- Document existing key chains
338338
spec = {
339-
{ '<leader>c', group = '[C]ode', mode = { 'n', 'x' } },
340-
{ '<leader>d', group = '[D]ocument' },
341-
{ '<leader>r', group = '[R]ename' },
342339
{ '<leader>s', group = '[S]earch' },
343-
{ '<leader>w', group = '[W]orkspace' },
344340
{ '<leader>t', group = '[T]oggle' },
345341
{ '<leader>h', group = 'Git [H]unk', mode = { 'n', 'v' } },
346342
},
@@ -532,42 +528,42 @@ require('lazy').setup({
532528
vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
533529
end
534530

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

540539
-- Find references for the word under your cursor.
541-
map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
540+
map('grr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
542541

543542
-- Jump to the implementation of the word under your cursor.
544543
-- Useful when your language has ways of declaring types without an actual implementation.
545-
map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
544+
map('gri', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
546545

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

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

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

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

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

0 commit comments

Comments
 (0)