cola
cola

Reputation: 12466

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

:colorscheme default

The filetype is php.

Can anyone help me to find out the highlight rule ?

Upvotes: 3

Views: 2972

Answers (3)

Don Reba
Don Reba

Reputation: 14041

I have something like this in my _gvimrc:

function! SyntaxBalloon()
    let synID   = synID(v:beval_lnum, v:beval_col, 0)
    let groupID = synIDtrans(synID)
    let name    = synIDattr(synID, "name")
    let group   = synIDattr(groupID, "name")
    return name . "\n" . group
endfunction

set balloonexpr=SyntaxBalloon()
set ballooneval

Upvotes: 2

mike3996
mike3996

Reputation: 17517

: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.

Upvotes: 7

Randy Morris
Randy Morris

Reputation: 40927

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.

Upvotes: 4

Related Questions