Tip 1573 Printable Monobook Previous Next

created June 22, 2008 · complexity basic · author Dominiko · version 7.0

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

First define a function which returns the highlight group syntax under the cursor:

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

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

Here is a screenshot example.

See also[edit | edit source]

References[edit | edit source]

Comments[edit | edit source]

Does not seem to work for standard groups like trailing characters, etc.

Community content is available under CC-BY-SA unless otherwise noted.