How to get group name under cursor in vim?

I usually customize the existing colorscheme to suit my needs.

If I could get the name of the syntax group under the cursor, that would help me a lot, like Firebug , but in Vim. I would like to know how to do this.

+12
source share
4 answers

This function that floated over the network when I did the same:

 function! SynStack() if !exists("*synstack") return endif echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")') endfunc 
+19
source

The following function displays both the name of the syntax group and the translated symbol syntax group on which 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, you can wrap it in a custom command or key binding.

How it works:

  • line('.') and col('.') return the current position
  • synID(...) returns the numerical syntax identifier
  • synIDtrans(l:s) converts the numeric syntax identifier of l:s , following the highlighted links
  • synIDattr(l:s, 'name') returns the name corresponding to the digital syntax identifier

It will sound something like this:

 vimMapModKey -> Special 
+11
source

Try the following:

 " diagnostics {{{ if has('balloon_eval') nnoremap <F12> : setl beval!<CR> set bexpr=InspectSynHL() endif fun! InspectSynHL() let l:synNames = [] let l:idx = 0 for id in synstack(v:beval_lnum, v:beval_col) call add(l:synNames, printf('%s%s', repeat(' ', idx), synIDattr(id, 'name'))) let l:idx+=1 endfor return join(l:synNames, "\n") endfun "}}} 
0
source

Here's a display that will show the synstack () hierarchy, and also show 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> 
0
source

Source: https://habr.com/ru/post/909446/


All Articles