I usually customize existing colorscheme
to meet my needs.
If I could get the syntax group name under cursor, it would help me a lot, just like Firebug but in Vim. I'd like to know how to do it.
There is this function that was floating around the web when I was doing the same thing:
function! SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
The following function will output both the name of the syntax group, and the translated syntax group of the character the cursor is on:
function! SynGroup()
let l:s = synID(line('.'), col('.'), 1)
echo synIDattr(l:s, 'name') . ' -> ' . synIDattr(synIDtrans(l:s), 'name')
endfun
To make this more convenient it can be wrapped in a custom command or key binding.
How this works:
line('.')
and col('.')
return the current positionsynID(...)
returns a numeric syntax IDsynIDtrans(l:s)
translates the numeric syntax id l:s
by following highlight linkssynIDattr(l:s, 'name')
returns the name corresponding to the numeric syntax IDThis will echo something like:
vimMapModKey -> Special
Here's a mapping that will show the hierarchy of the synstack() and also show the highlight links. press gm to use it.
function! SynStack ()
for i1 in synstack(line("."), col("."))
let i2 = synIDtrans(i1)
let n1 = synIDattr(i1, "name")
let n2 = synIDattr(i2, "name")
echo n1 "->" n2
endfor
endfunction
map gm :call SynStack()<CR>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With