How do I enable LSP inlay hints to show types and parameter names inline in Neovim?
Answer
:lua vim.lsp.inlay_hint.enable()
Explanation
Neovim 0.10 introduced built-in support for LSP inlay hints via vim.lsp.inlay_hint. Inlay hints are virtual text annotations injected by the language server directly into your code to show inferred types, parameter names, and return types — making the code more readable without changing the actual file content.
How it works
- Enable globally:
:lua vim.lsp.inlay_hint.enable()turns on inlay hints for the current buffer - Disable:
:lua vim.lsp.inlay_hint.enable(false)or:lua vim.lsp.inlay_hint.enable(0, {enabled = false}) - Toggle:
:lua vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled()) - In vimrc:
vim.lsp.inlay_hint.enable()inside anLspAttachautocommand
Example
With rust-analyzer attached to a Rust file:
let x = add(1, 2); → let x /*: i32*/ = add(/*a:*/ 1, /*b:*/ 2);
The type : i32 and parameter names a:, b: appear as greyed-out virtual text.
Tips
- Inlay hints require the language server to support the
textDocument/inlayHintcapability (rust-analyzer, clangd, gopls, and tsserver all do) - To enable globally on every LSP attach, add to your init.lua:
autocmd LspAttach * lua vim.lsp.inlay_hint.enable()
- Customize the appearance by linking the
LspInlayHinthighlight group to another group - Use
:lua print(vim.inspect(vim.lsp.inlay_hint.get()))to inspect the current buffer's hint list