Skip to main content
Add explanation
Source Link

To get the highlight group that a group links to, you can use this function:

function! GetLinkTarget(group)
    let l:groupID = hlID(a:group)
    " Get the group this highlight group links to
    let l:linkedGroupID = synIDtrans(l:groupID)
    let l:linkedGroupName = synIDattr(l:linkedGroupID, 'name')
    echom a:group . " → " . l:linkedGroupName
endfunction

Example usage:

:call GetLinkTarget("vim9Comment")

Output:

vim9Comment → Comment

Explanation:

  1. hlID gets the ID of the highlight group whose linked to highlight group we want to find out.
  2. synIDtrans(l:groupID) gets the ID of the linked to group.
  3. synIDattr(l:linkedGroupID, 'name') translates the ID of the linked to group to its name.
function! GetLinkTarget(group)
    let l:groupID = hlID(a:group)
    " Get the group this highlight group links to
    let l:linkedGroupID = synIDtrans(l:groupID)
    let l:linkedGroupName = synIDattr(l:linkedGroupID, 'name')
    echom a:group . " → " . l:linkedGroupName
endfunction

Example usage:

:call GetLinkTarget("vim9Comment")

Output:

vim9Comment → Comment

To get the highlight group that a group links to, you can use this function:

function! GetLinkTarget(group)
    let l:groupID = hlID(a:group)
    " Get the group this highlight group links to
    let l:linkedGroupID = synIDtrans(l:groupID)
    let l:linkedGroupName = synIDattr(l:linkedGroupID, 'name')
    echom a:group . " → " . l:linkedGroupName
endfunction

Example usage:

:call GetLinkTarget("vim9Comment")

Output:

vim9Comment → Comment

Explanation:

  1. hlID gets the ID of the highlight group whose linked to highlight group we want to find out.
  2. synIDtrans(l:groupID) gets the ID of the linked to group.
  3. synIDattr(l:linkedGroupID, 'name') translates the ID of the linked to group to its name.
Source Link

function! GetLinkTarget(group)
    let l:groupID = hlID(a:group)
    " Get the group this highlight group links to
    let l:linkedGroupID = synIDtrans(l:groupID)
    let l:linkedGroupName = synIDattr(l:linkedGroupID, 'name')
    echom a:group . " → " . l:linkedGroupName
endfunction

Example usage:

:call GetLinkTarget("vim9Comment")

Output:

vim9Comment → Comment