History Report a problem
Article Edit this page Discussion

Identify the syntax highlighting group used at the cursor

From Vim Tips Wiki

Jump to: navigation, search
 

Tip 99Previous TipNext Tip

Created: August 14, 2001 Complexity: intermediate Author: Charles E. Campbell, Jr. Minimum version: 5.7 Karma: 82/34 Imported from: Tip#99


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, check out:

http://mysite.verizon.net/astronaut/index.html

See also :help synstack() ← relatively new feature, may need to view in Vim itself.

[edit] Comments

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

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

Put the cursor on the "\(" in the string, hit <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".


Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Terminator Wiki
Legend of Zelda Wiki
Flash Gordon
Everquest II Wiki
Yo-Yo Wiki
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions


Vote for featured Wikia!

Send this article to a friend
"Identify the syntax highlighting group used at the cursor"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation