Vim Tips Wiki
Advertisement

You can show the syntax highlight group where the cursor is located in your statusbar. This is especially useful when tweaking a color theme.

  function! SyntaxItem()
    return synIDattr(synID(line("."),col("."),1),"name")
  endfunction

Then insert into your statusline a call to function SyntaxItem:

  set statusline+=%{SyntaxItem()}

Here is a complete example showing the syntax highlight group among other things:

  if has('statusline')
    set statusline=%#Question#                   " set highlighting
    set statusline+=%-2.2n\                      " buffer number
    set statusline+=%#WarningMsg#                " set highlighting
    set statusline+=%f\                          " file name
    set statusline+=%#Question#                  " set highlighting
    set statusline+=%h%m%r%w\                    " flags
    set statusline+=%{strlen(&ft)?&ft:'none'},   " file type
    set statusline+=%{(&fenc==\"\"?&enc:&fenc)}, " encoding
    set statusline+=%{((exists(\"+bomb\")\ &&\ &bomb)?\"B,\":\"\")} " BOM
    set statusline+=%{&fileformat},              " file format
    set statusline+=%{&spelllang},               " language of spelling checker
    set statusline+=%{SyntaxItem()}              " syntax highlight group under cursor
    set statusline+=%=                           " ident to the right
    set statusline+=0x%-8B\                      " character code under cursor
    set statusline+=%-7.(%l,%c%V%)\ %<%P         " cursor position/offset
  endif

Here is a screenshot example.

References

Advertisement