Links
- Syntax files
- Sites: syntax colors
- Default highlight-groups
- Portable syntax file layout
- Adding to an existing syntax file
- Syntax Pattern Offset
- Syntax Cluster
- Wiki: Creating your own syntax files
- Including other syntax files
- Different syntax highlighting within regions of a file
- syn-include
- Note also that you can define
syntax/after/name.vim
to define post syntax stuff. - If you want a full include, like say for
cpp.vim
to includec.vim
, then do something like:runtime! syntax/c.vim
unlet b:current_syntax
- If you want to use a different syntax within a
region, such as Javascript syntax inside the script
element of an html file, then do something like:
:syntax include [@{grouplist-name}] {file-name}
- All syntax items declared in the included file will have the
contained
flag added. - In addition, if a group list is specified, all top-level syntax items in the included file will be added to that list.
- e.g., in
perl.vim
syntax include @Pod <sfile>:p:h/pod.vim
syntax region perlPOD start="^=head" end="^=cut" contains=@Pod
- Fix syntax highlighting
- :syntax sync
syntax sync fromstart | syn off | syn on
syntax sync minlines=400 | syn off | syn on
- synIDattr()
- synIDtrans()
- Conceal
Filetype
Misc
syntax sync fromstart syntax sync minlines=200 " Reloading a syntax. syntax clear runtime syntax/python.vim
Syntax
From Sites: syntax colors
This command switches on syntax highlighting:
:syntax enable
The ":syntax enable" command will keep your current color settings. This allows using ":highlight" commands to set your preferred colors before or after using this command. If you want Vim to overrule your settings with the defaults, use:
:syntax on
You can start using your syntax file manually:
:set syntax=mine
When a language is a superset of another language, it may include the other one, for example, the cpp.vim file could include the c.vim file:
:so $VIMRUNTIME/syntax/c.vim
The .vim files are normally loaded with an autocommand. For example:
:au Syntax c runtime! syntax/c.vim :au Syntax cpp runtime! syntax/cpp.vim
These commands are normally in the file $VIMRUNTIME/syntax/synload.vim
.
Defining a syntax: syn-define
Vim understands three types of syntax items:
-
Keyword
It can only contain keyword characters, according to the 'iskeyword'
option. It cannot contain other syntax items. It will only match with a
complete word (there are no keyword characters before or after the match).
The keyword "if" would match in "if(a=b)", but not in "ifdef x", because
"(" is not a keyword character and "d" is. -
Match
This is a match with a single regexp pattern. -
Region
This starts at a match of the "start" regexp pattern and ends with a match
with the "end" regexp pattern. Any other text can appear in between. A
"skip" regexp pattern can be used to avoid matching the "end" pattern.
Several syntax ITEMs can be put into one syntax GROUP. For a syntax group
you can give highlighting attributes. For example, you could have an item
to define a "/ .. /" comment and another one that defines a "// .." comment,
and put them both in the "Comment" group. You can then specify that a
"Comment" will be in bold font and have a blue color. You are free to make
one highlight group for one syntax item, or put all items into one group.
This depends on how you want to specify your highlighting attributes. Putting
each item in its own group results in having to specify the highlighting
for a lot of groups.
Note that a syntax group and a highlight group are similar. For a highlight
group you will have given highlight attributes. These attributes will be used
for the syntax group with the same name.
In case more than one item matches at the same position, the one that was
defined LAST wins. Thus you can override previously defined syntax items by
using an item that matches the same text. But a keyword always goes before a
match or region. And a keyword with matching case always goes before a
keyword with ignoring case.
PRIORITY: syn-priority
When several syntax items may match, these rules are used:
- When multiple Match or Region items start in the same position, the item
defined last has priority. - A Keyword has priority over Match and Region items.
- An item that starts in an earlier position has priority over items that
start in later positions.
DEFINING CASE: syn-case
:sy[ntax] case [match | ignore]
This defines if the following ":syntax" commands will work with
matching case, when using "match", or with ignoring case, when using
"ignore". Note that any items before this are not affected, and all
items until the next ":syntax case" command are affected.