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

How do I see exactly which highlight groups are responsible for the color of the character under the cursor in Neovim?

Answer

:Inspect

Explanation

When customizing a colorscheme or debugging unexpected syntax colors, it's difficult to know which highlight group to override. Neovim 0.9+ provides :Inspect, which opens a floating window listing every highlight layer stacked on the character under the cursor — treesitter captures, legacy syntax groups, LSP semantic tokens, and any extmark-based highlights — along with their resolved colors and where they come from.

How it works

Position the cursor on any character and run :Inspect. Neovim shows a popup like:

Treesitter
  @function.call  →  Function  guifg=#82aaff

Syntax
  Function
  Identifier

Each layer is listed with its priority. The winning group (the one actually rendered) appears at the top. Linked highlight groups show the chain: @function.call → Function means @function.call links to the built-in Function group.

Example workflow

If a keyword looks the wrong color:

  1. Move the cursor onto the keyword
  2. Run :Inspect
  3. Note the top highlight group — e.g., @keyword.return linked to Statement
  4. Override in your config:
:highlight @keyword.return guifg=#ff9e64

Tips

  • Pair with :InspectTree to see the full treesitter parse tree and understand which node type generated the highlight
  • For scripting equivalents in older Vim/Neovim, use synID(), synIDtrans(), and synIDattr() to query highlight info programmatically
  • :Inspect works even for highlights applied by LSP (semantic tokens) which are invisible to :syntax list
  • This command is available in Neovim 0.9+ only; classic Vim does not have it

Next

How do I prepend a value to the front of a comma-separated Vim option like path or runtimepath?