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

How do I use Neovim's built-in default LSP keymaps for rename, references, and code actions?

Answer

grn

Explanation

Neovim 0.11 introduced a set of default LSP keymaps that are automatically active whenever an LSP client attaches to a buffer. These eliminate the need to manually define the most common LSP bindings in your config, providing a consistent baseline across machines and fresh installs.

How it works

The default LSP keymaps (normal mode unless noted):

  • grn — rename the symbol under the cursor (vim.lsp.buf.rename())
  • grr — list all references for the symbol under the cursor (vim.lsp.buf.references())
  • gra — select a code action at the cursor position (vim.lsp.buf.code_action())
  • gri — list all implementations (vim.lsp.buf.implementation())
  • <C-s> (insert mode) — show signature help (vim.lsp.buf.signature_help())

These are automatically set in LspAttach when no manual override is present. They respect vim.keymap.set() priority, so your own mappings always take precedence.

Example

With an LSP client active on a Python file, place your cursor on a function name and press:

grn

This opens an input prompt to rename the symbol across the entire project.

Tips

  • These defaults are available in Neovim 0.11+; in earlier versions you must define them manually
  • You can disable a specific default by defining your own map for the same key: vim.keymap.set('n', 'grn', ...) in your LspAttach autocmd
  • Combine with vim.diagnostic.setloclist() (<leader>q by default) to view all buffer diagnostics

Next

How do I make Neovim restore the scroll position when navigating back through the jump list?