How do I rename a symbol under the cursor using Neovim's built-in LSP without any plugin configuration?
Answer
grr
Explanation
Since Neovim 0.10, a set of default LSP keymaps is automatically registered whenever a language server attaches to a buffer. One of the most useful is grr, which triggers a rename refactor on the symbol under the cursor — no nvim-lspconfig mapping or manual vim.keymap.set required.
How it works
Neovim 0.10 registers these keymaps via an internal LspAttach autocommand whenever an LSP client attaches:
grr " vim.lsp.buf.rename() — rename the symbol
gra " vim.lsp.buf.code_action() — trigger code action
gri " vim.lsp.buf.implementation() — go to implementation
gO " vim.lsp.buf.document_symbol() — list document symbols
In Insert mode, <C-S> calls vim.lsp.buf.signature_help().
Example
With a Python file open and pyright attached:
1. Place cursor on a function name: my_func
2. Press grr
3. A prompt appears: "New name:"
4. Type the new name and press Enter
5. All references in the project are renamed
Tips
- These keymaps are only active in buffers where an LSP client has attached; they do not conflict with mappings in other buffers
- You can verify which LSP clients are attached with
:checkhealth lspor:LspInfo - To disable the default keymaps, set
vim.g.lsp_enable_default_keymaps = falsebefore theLspAttachevent fires - The
gracode action works on both the current line and a visual selection