I'm working on a small vim plugin which should highlight current word occurrences after cursor idle. I have a highlight part, and what I need is to check if the current word is not a C/C++ keyword.
You can do that depending on current syntax highlight script. Say, this function returns if your cursor is on some access modifier (public, protected, etc), or some C++ type (say, bool, etc) :
function! IsCppAccessOrType()
return match(synIDattr(synID(line("."), col("."), 1), "name"), '\v\CcppAccess|cppType') >= 0
endfunction
But, again, this will completely depend on current syntax script. Example above depends on standard syntax/cpp.vim provided with Vim 7.3 .
By the way, there is very useful trick to deal with syntax highlight stuff:
" Show syntax highlighting groups for word under cursor
nnoremap <silent> <F10> :call <SID>SynStack()<CR>
function! <SID>SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
Add this to your vimrc, and when you press F10, stack of syntax items will be echoed ( see :help synstack for more details ).
I have found this trick somewhere on http://vimbits.com .
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