Skip to content

Instantly share code, notes, and snippets.

@changemewtf
Last active April 11, 2017 16:52
Show Gist options
  • Save changemewtf/7bff61685e8b17acee56d977b025a705 to your computer and use it in GitHub Desktop.
Save changemewtf/7bff61685e8b17acee56d977b025a705 to your computer and use it in GitHub Desktop.
A utility function for debugging syntax highlight "situations".
" Produces output like:
" vimOption (PreProc fg=225 bg=) < vimSet (fg= bg=) < vimFuncBody (fg= bg=)
nnoremap g<C-h> :echo GetSynInfo()<CR>
function! GetSynInfo()
let stack = synstack(line("."), col("."))
let info = ""
for synid in reverse(stack)
if strlen(info)
let info .= " < "
endif
let syn = GetSynDict(synid)
let info .= GetSynInfoString(syn)
endfor
return info
endfunction
function! GetSynInfoString(syndict)
if a:syndict["syn"] != a:syndict["hi"]
let add_hi = a:syndict["hi"]." "
else
let add_hi = ""
endif
return a:syndict["syn"]." (".add_hi."fg=".a:syndict["fg"]." bg=".a:syndict["bg"].")"
endfunction
function! GetHereSynId(trans)
return synID(line("."), col("."), a:trans)
endfunction
function! GetSynDict(synid)
let hiid = synIDtrans(a:synid)
let syn = synIDattr(a:synid, "name")
let hi = synIDattr(hiid, "name")
let fg = synIDattr(hiid, "fg")
let bg = synIDattr(hiid, "bg")
return {"syn":syn, "hi":hi, "fg":fg, "bg":bg}
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment