7

Ok folks, I've tried all these duplicates:

But none of them work in for me in Neovim (0.8.2). And the plugin at https://github.com/benknoble/vim-synstax more helpfully reports "No syntax highlight groups under cursor".

I'm testing by putting my cursor in a word in a highlighted PHP doc and then firing the suggested command(s).

I just want my comments to be more readable (they're dark grey on black at the moment).

Is Neovim really different? Is it because I'm using Treesitter?

EDIT

Running without any plugins, the above answers work, it seems to be treesitter that causes the problem.

A minimal config is

use {
'nvim-treesitter/nvim-treesitter',
config = function()
  require('nvim-treesitter.configs').setup({
    highlight = { enable: true }
  })
  end,
}

Note that the problem only seems to occur when the treesitter's config specifies to enable highlight.

2
  • 1
    I suppose we will need a bit more information in order to reproduce the problem. Could you reproduce the problem on a minimal configuration (reduce at maximum the number of plugin that you install and limit the vimrc to the bare minimum). Let us know what you need to reproduce the problem. It will help us to reproduce and to help :-) Jan 13, 2023 at 15:20
  • Along with minimal configuration, commands necessary after running vim to reproduce would be helpful
    – D. Ben Knoble
    Jan 14, 2023 at 20:27

3 Answers 3

5

For those using Neovim 0.9.0 (or newer), it now includes a command that does what you asked for (provided by a bundled runtime plugin):

:Inspect

Sources:

https://github.com/neovim/neovim/releases/tag/v0.9.0

https://github.com/neovim/neovim/pull/21393

10

Neovim v0.9

The following commands are now available built-in, which do what you want

:Inspect             " prints as nicely formatted text
:Inspect!            " prints as a lua table

The lua API also has equivalent functions

vim.show_pos()       -- Similar to :Inspect (prints text)
vim.inspect_pos()    -- Similar to :Inspect! (returns table)

Beyond giving the highlight group for the cursor position, the output gives information on

  • treesitter: a list of treesitter captures
  • syntax: a list of syntax groups
  • semantic_tokens: a list of semantic tokens
  • extmarks: a list of extmarks

See :h lua-insector

Neovim v0.8 (original answer)

From 'nvim-treesitter/playground', there is the command

:TSHighlightCapturesUnderCursor

which does exactly this, presenting a nice popup at your cursor location. It works similarly to

:TSNodeUnderCursor

to get the tree-sitter node at your cursor location.

2

According to the closed issue at
https://github.com/nvim-treesitter/nvim-treesitter/issues/1654#issuecomment-893756730
Treesitter messes up synstack().

The only way to get a function to do something similar is through installing a 2nd plugin, nvim-treesitter/playground and writing a lua function, like the one at https://github.com/urbainvaes/vim-macaw/commit/be633f850fb54ed71cc6a1d46ee788380b7393b5

Manually, once you have playground installed you can start it up with :TSPlaygroundToggle then in the playground window press i to show highlight groups.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.