Wikia

Vim Tips Wiki

Changes: Showing syntax highlight group in statusline

Edit

Back to page

(Insert TipProposed template + minor manual clean)
(Assign tip id + convert to TipNew template)
Line 1: Line 1:
{{TipProposed
+
{{TipNew
|id=0
+
|id=1573
|previous=0
+
|previous=1572
|next=0
+
|next=1574
 
|created=June 22, 2008
 
|created=June 22, 2008
 
|complexity=basic
 
|complexity=basic

Revision as of 05:58, September 10, 2008

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")
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.

See also

References

Comments

Around Wikia's network

Random Wiki