vimtricks.wiki Concise Vim tricks, one at a time.

What built-in LSP keymaps does Neovim 0.10+ provide automatically when a language server is attached?

Answer

grn, gra, grr, gri

Explanation

Starting with Neovim 0.10, a set of useful LSP keymaps are defined automatically in every buffer where a language server attaches — no manual on_attach configuration required. This means a minimal LSP setup (e.g., just calling vim.lsp.start() or a plugin like nvim-lspconfig) gives you full refactoring and navigation keybindings out of the box.

How it works

Neovim registers these default keymaps on LspAttach:

Keymap Action Vimscript equivalent
grn Rename symbol vim.lsp.buf.rename()
gra Code action vim.lsp.buf.code_action()
grr List references vim.lsp.buf.references()
gri Go to implementation vim.lsp.buf.implementation()
gO Document symbols vim.lsp.buf.document_symbol()
<C-S> (insert) Signature help vim.lsp.buf.signature_help()

Long-standing keymaps like K (hover) and gd (definition) also work with LSP as they did before.

Example

With an LSP attached to a TypeScript file:

" Place cursor on a variable and press:
grn          " rename across the project
gra          " show available code actions (fix imports, etc.)
grr          " list all references in the quickfix window

Tips

  • To override a default, define the mapping in your LspAttach autocmd with buffer = args.buf
  • Use :map grn to inspect the current binding and confirm it points to the LSP action
  • Check :help lsp-defaults for the complete list maintained in Neovim's docs

Next

How do I define custom fold marker strings instead of the default {{{ }}} in Vim?