Colors are no longer specified by syntax files, but are instead pulled from
color schemes. This requires syntax and color scheme files to share a
common convention so that colors can neatly propagate into syntax
highlighting as intended. All of the builtin syntax files and schemes
follow the convention that is described here.
To review, the color classes in syntax files must either match a class found
in the color scheme, or reference one. For example:
=Constant
=String +Constant
String
will be the first of these to apply:
<syntax name>.String
as defined in the color schemeString
as defined in the color scheme<syntax name>.Constant
as defined in the color schemeConstant
as defined in the color schemeMultiple "fallback" classes can be referenced in a class definition; JOE
will take the first that exists. This example is fairly straightforward, as
the constant class can be thought of as a superset of strings. In this
manner, a hierarchy of language elements emerges.
Generally, a color scheme should be able to get good mileage by defining a
very minimal set of classes: Constant
, Comment
, Keyword
, Type
, and
Preproc
will produce a satisfactory result for most languages.
Naturally, there are outliers. diff
and xml
are both very common and
don't fit neatly into the hierarchy that works for most other languages.
This is worked around by making new classes specific to each's respective
syntaxes and falling back to color classes that are likely to be distinct.
In these specific cases, fallback color classes were chosen based on which
classes were inherited from in vim for those elements. (Though in practice,
the existing schemes specify classes for xml and diff specifically).
In general, it's OK for each syntax file to define classes that are not on
this list as the designer sees fit, as long as they can be mapped to
something sensible from the list. The intended design is that the syntax
files proffer up as many of the language elements as feasible, the color
scheme provides a palette, and the class definitions map between the two.
What follows are the most common classes used among the existing syntaxes:
what entities in languages they describe, what other classes they can
inherit their colors from. New syntaxes should use these class definitions
verbatim unless there's a good reason to inherit from something else
(exceptions abound in the built-in syntaxes).
While it's best to study the built-in syntaxes, this list should serve as a
reasonable summary and reference, especially where the intent is otherwise
unclear.
=Idle
=Ident
=Bad
=DefinedIdent +Ident
=DefinedFunction +DefinedIdent
DefinedIdent
. This is the identifier in a function=DefinedType +DefinedIdent
DefinedIdent
. This is the identifier in a type=Label +DefinedIdent
=Preproc
=Precond +Preproc
=Define +DefinedIdent +Preproc
=Include +Preproc
=IncLocal +String +Preproc
=IncSystem +Preproc +Keyword
=Attribute +Define +Preproc
=Comment
=TODO +Comment
=Constant
=Number +Constant
=Boolean +Constant
true
or false
=String +Constant
=Escape
=StringEscape +Escape +String
=Character +String +Constant
=CharacterEscape +StringEscape +Character
=Regex +String
=RegexEscape +StringEscape
=Variable +Escape
$foo
or %bar%
=Docstring +Comment
=DocstringLabel +Docstring
TODO
in docstrings in Python. Should be renamed.=DocEscape +Escape +Docstring
=StringVariable +StringEscape
=RegexVariable +StringEscape
=Keyword
=Statement +Keyword
for
, if
, switch
, etc in C.=Loop +Statement
=Conditional +Statement
=Operator +Keyword
in
, is
, etc+
, *
, -
, /
, etc. Those are typically handled by Control
.=Type
=StorageClass +Type +Keyword
volatile
, static
,const
, etc.=Structure +Type +Keyword
struct
, class
, etc.=Brace
{
, }
=Control
=Builtin +DefinedFunction
len
.(Yes, the bases are weird for diff)
=diff.DelLine +Escape
=diff.AddLine +DefinedIdent
=diff.ChgLine +Preproc
=CppKeyword +Keyword
=Tag +DefinedFunction +DefinedIdent
=TagName +Tag
=TagEnd +Tag
=Attr +Type
=Entity +Escape
=StringEntity +StringEscape +Entity
=Title
=Namespace +Comment
More in XML and HTML:
* PIStart
, PIBody
, PIEnd
* CdataEdge
, CdataBody
* Decl