2

I want to design my own vim color scheme, so I'm starting with an existing color scheme that I think is pretty good, and fixing the parts I don't like.

The color scheme definition contains many syntax tags, a lot of which aren't totally clear. The task would be much easier if I could ask Vim:

Which syntax rule is determining the color of the character under my cursor?

Is there a way to do it?

2

There are plenty. One is my own plugin, the code of which is straightforward:

" Show the highlight groups under the cursor
" Maintainer:       David Ben Knoble <ben.knoble@gmail.com>
" Last Change:      2018 May 11

if !has("syntax") || &compatible
  echohl ErrorMsg
  echomsg "vim-synstax requires the +syntax features"
  echohl None
  finish
endif

function! synstax#UnderCursor() abort
  let l:stack = synstax#Stack(line('.'), col('.'))
  if empty(l:stack)
    return "No syntax highlight groups under cursor"
  endif
  let l:names = synstax#Attributes(l:stack, 'name')
  return l:names
endfunction

function! synstax#Stack(line, col) abort
  return synstack(a:line, a:col)
endfunction

function! synstax#Attributes(stack, attr) abort
  let l:attr_func = printf('synIDattr(v:val, "%s")', a:attr)
  return map(a:stack, l:attr_func)
endfunction

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.