Skip to content

Commit c74a44a

Browse files
committed
Update LSP Keybindings to Match the Default gr Bindings Introduced in Neovim 0.11
Partially cherry-picked nvim-lua@1a5787b PR nvim-lua#1427
1 parent 83feb08 commit c74a44a

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

init.lua

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -598,42 +598,56 @@ require('lazy').setup({
598598
vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
599599
end
600600

601+
-- NOTE:
602+
-- With Neovim v0.11 `gr` is a prefix for a bunch of code actions
603+
-- https://github.com/nvim-lua/kickstart.nvim/pull/1427
604+
-- Commented out the old mapping, let's see how it evolves..
605+
601606
-- Jump to the definition of the word under your cursor.
602607
-- This is where a variable was first declared, or where a function is defined, etc.
603608
-- To jump back, press <C-t>.
604609
map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
610+
map('grd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
611+
612+
-- Rename the variable under your cursor.
613+
-- Most Language Servers support renaming across files, etc.
614+
-- map('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
615+
map('grn', vim.lsp.buf.rename, '[R]e[n]ame')
616+
617+
-- Execute a code action, usually your cursor needs to be on top of an error
618+
-- or a suggestion from your LSP for this to activate.
619+
-- map('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction', { 'n', 'x' })
620+
map('gra', vim.lsp.buf.code_action, '[G]oto Code [A]ction', { 'n', 'x' })
605621

606622
-- Find references for the word under your cursor.
607-
map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
623+
-- map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
624+
map('grr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
608625

609626
-- Jump to the implementation of the word under your cursor.
610627
-- Useful when your language has ways of declaring types without an actual implementation.
611-
map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
628+
-- map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
629+
map('gri', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
630+
631+
-- WARN: This is not Goto Definition, this is Goto Declaration.
632+
-- For example, in C this would take you to the header.
633+
-- map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
634+
map('grD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
612635

613636
-- Jump to the type of the word under your cursor.
614637
-- Useful when you're not sure what type a variable is and you want to see
615638
-- the definition of its *type*, not where it was *defined*.
616-
map('<leader>D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition')
639+
-- map('<leader>D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition')
640+
map('grt', require('telescope.builtin').lsp_type_definitions, '[G]oto [T]ype Definition')
617641

618642
-- Fuzzy find all the symbols in your current document.
619643
-- Symbols are things like variables, functions, types, etc.
620-
map('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
644+
-- map('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
645+
map('gO', require('telescope.builtin').lsp_document_symbols, 'Open Document Symbols')
621646

622647
-- Fuzzy find all the symbols in your current workspace.
623648
-- Similar to document symbols, except searches over your entire project.
624-
map('<leader>Ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
625-
626-
-- Rename the variable under your cursor.
627-
-- Most Language Servers support renaming across files, etc.
628-
map('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
629-
630-
-- Execute a code action, usually your cursor needs to be on top of an error
631-
-- or a suggestion from your LSP for this to activate.
632-
map('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction', { 'n', 'x' })
633-
634-
-- WARN: This is not Goto Definition, this is Goto Declaration.
635-
-- For example, in C this would take you to the header.
636-
map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
649+
-- map('<leader>Ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
650+
map('gW', require('telescope.builtin').lsp_dynamic_workspace_symbols, 'Open Workspace Symbols')
637651

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

0 commit comments

Comments
 (0)