Wikia

Vim Tips Wiki

Changes: Identify the syntax highlighting group used at the cursor

Edit

Back to page

(fix DrChip changed URL + minor manual clean)
(fix DrChip changed URL + minor manual clean)
 
Line 20: Line 20:
 
Once known you can override the current highlighting with whatever you want.
 
Once known you can override the current highlighting with whatever you want.
   
If you're debugging a syntax highlighting file (a rare occupation), sometimes you'll wish to know the entire chain of syntax highlighting. For that, check out: http://drchip.0sites.net/astronaut/vim/index.html#HILINKS
+
If you're debugging a syntax highlighting file (a rare occupation), sometimes you'll wish to know the entire chain of syntax highlighting. For that, see [http://www.drchip.org/astronaut/vim/index.html#HILINKS HiLinkTrace].
   
 
See also {{help|synstack()}}
 
See also {{help|synstack()}}
Line 31: Line 31:
 
syn match vimSpecFile "<c\(word\|WORD\)>" nextgroup=...
 
syn match vimSpecFile "<c\(word\|WORD\)>" nextgroup=...
   
Put the cursor on the "\(" in the string, hit <F10>:
+
Put the cursor on the "\(" in the string, press F10:
 
hi<vimPatSep> trans<vimPatSep> lo<Special>
 
hi<vimPatSep> trans<vimPatSep> lo<Special>
 
will show up on the status line. You may envisage the highlighting as a push-down stack of highlighting groups. The "highest" one is the most limited in scope, and is the name of the syntax keyword, match, or region. Generally such a syntax group is linked to a highlighting group. The "lowest" one is the basic highlighting specification, and probably has a broad reach -- in this case, "Special" is a default highlighting group used in 179 syntax highlighting files (vim 6.0) for a variety of purposes.
 
will show up on the status line. You may envisage the highlighting as a push-down stack of highlighting groups. The "highest" one is the most limited in scope, and is the name of the syntax keyword, match, or region. Generally such a syntax group is linked to a highlighting group. The "lowest" one is the basic highlighting specification, and probably has a broad reach -- in this case, "Special" is a default highlighting group used in 179 syntax highlighting files (vim 6.0) for a variety of purposes.

Latest revision as of 02:04, March 8, 2012

Tip 99 Printable Monobook Previous Next

created 2001 · complexity intermediate · author Charles E. Campbell, Jr. · version 6.0


Here's a (what should be a one-line) map to help you tell just what syntax highlighting groups the item under the cursor actually is:

map <F10> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>

Once known you can override the current highlighting with whatever you want.

If you're debugging a syntax highlighting file (a rare occupation), sometimes you'll wish to know the entire chain of syntax highlighting. For that, see HiLinkTrace.

See also :help synstack()

See alsoEdit

CommentsEdit

Example: Looking at the syntax/vim.vim file's

syn match vimSpecFile "<c\(word\|WORD\)>" nextgroup=...

Put the cursor on the "\(" in the string, press F10:

hi<vimPatSep> trans<vimPatSep> lo<Special>

will show up on the status line. You may envisage the highlighting as a push-down stack of highlighting groups. The "highest" one is the most limited in scope, and is the name of the syntax keyword, match, or region. Generally such a syntax group is linked to a highlighting group. The "lowest" one is the basic highlighting specification, and probably has a broad reach -- in this case, "Special" is a default highlighting group used in 179 syntax highlighting files (vim 6.0) for a variety of purposes.

Syntax groups can be specified as being transparent, so that whatever group they're in is what is used for highlighting. If that's the case, the group mentioned in "trans<>" will be the name of that group, else it is a repeat of the "hi<>" group name.

With the highlighting script (hilinks.vim), you'll get (via \hlt):

vimPatSep -> SpecialChar -> Special

which shows the entire highlighting chain. Thus, a "\(" is identified as being highlighted as a vimPatSep, which is a link to SpecialChar, which itself is a link to Special. Actually a "\(" is a vimPatSepZone region which has vimPatSep as its "matchgroup".


Around Wikia's network

Random Wiki