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

会有一股神秘感。 提交于 2019-12-13 02:49:55

问题


:colorscheme default

The filetype is php.

Can anyone help me to find out the highlight rule ?


回答1:


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



回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/7893445/vim-how-can-i-know-which-highlight-rule-is-being-used-for-a-keyword

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!