Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM: How can i know which highlight rule is being used for a keyword?

Tags:

vim

editor

:colorscheme default

The filetype is php.

Can anyone help me to find out the highlight rule ?

like image 808
shibly Avatar asked Dec 04 '25 19:12

shibly


2 Answers

:hi[light]

will list all defined rules with a preview. You can also query single items:

:hi Keyword

To manually look up any syntax group under the cursor, there are choices. Mine is a function bounded to a key like this:

" Show syntax highlighting groups for word under cursor
nmap <F2> :call <SID>SynStack()<CR>
function! <SID>SynStack()
    if !exists("*synstack")
        return
    endif
    echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc

It'll list every syntax group the word belongs to.

like image 187
mike3996 Avatar answered Dec 06 '25 12:12

mike3996


I've had the following snippet tucked away for a while now, not sure where I got it. This will set your statusline to show the highlight group of the word currently under the cursor:

:set statusline=%{synIDattr(synIDtrans(synID(line('.'),col('.'),1)),'name')}

This will update your statusline as you move around the file.

like image 32
Randy Morris Avatar answered Dec 06 '25 11:12

Randy Morris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!