Skip to content

Instantly share code, notes, and snippets.

@akiya64
Created May 6, 2023 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akiya64/6533dcc0b29bb254777ee74b8cecd6ca to your computer and use it in GitHub Desktop.
Save akiya64/6533dcc0b29bb254777ee74b8cecd6ca to your computer and use it in GitHub Desktop.
:ShowRootHighlightUnderCursor
vim.api.nvim_create_user_command('ShowRootHighlightUnderCursor', function()
local function findRoot(id, tree)
local transId = vim.fn.synIDtrans(id)
local name = vim.fn.synIDattr(id, 'name')
table.insert(tree, name)
if id == transId then
print(table.concat(tree, ' -> '))
else
findRoot(transId, tree)
end
end
local id = vim.fn.synID(vim.fn.line("."), vim.fn.col("."), 0)
findRoot(id, {})
end, {})
@ndom91
Copy link

ndom91 commented Oct 8, 2023

By cursor you don't mean mouse cursor, right?

I can't get this to print anything at all 🤔

When executing the user command and my cursor is over a JS variable, for example, it just throws an empty notification window (I changed print to vim.notify).

Any idea what could be going on here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment