Skip to content

Commit f0ff3b0

Browse files
theopnThanh Danh
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 dca2e4c commit f0ff3b0

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
@@ -481,11 +481,7 @@ require('lazy').setup({ -- NOTE: Plugins can be added with a link (or for a gith
481481

482482
-- Document existing key chains
483483
spec = {
484-
{ '<leader>c', group = '[C]ode', mode = { 'n', 'x' } },
485-
{ '<leader>d', group = '[D]ocument' },
486-
{ '<leader>r', group = '[R]ename' },
487484
{ '<leader>s', group = '[S]earch' },
488-
{ '<leader>w', group = '[W]orkspace' },
489485
{ '<leader>t', group = '[T]oggle' },
490486
{ '<leader>h', group = 'Git [H]unk', mode = { 'n', 'v' } },
491487
},
@@ -707,42 +703,42 @@ require('lazy').setup({ -- NOTE: Plugins can be added with a link (or for a gith
707703
vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
708704
end
709705

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

715714
-- Find references for the word under your cursor.
716-
map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
715+
map('grr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
717716

718717
-- Jump to the implementation of the word under your cursor.
719718
-- Useful when your language has ways of declaring types without an actual implementation.
720-
map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
719+
map('gri', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
721720

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

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

731734
-- Fuzzy find all the symbols in your current workspace.
732735
-- Similar to document symbols, except searches over your entire project.
733-
map('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
734-
735-
-- Rename the variable under your cursor.
736-
-- Most Language Servers support renaming across files, etc.
737-
map('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
738-
739-
-- Execute a code action, usually your cursor needs to be on top of an error
740-
-- or a suggestion from your LSP for this to activate.
741-
map('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction', { 'n', 'x' })
736+
map('gW', require('telescope.builtin').lsp_dynamic_workspace_symbols, 'Open Workspace Symbols')
742737

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

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

0 commit comments

Comments
 (0)