syntax 

Send to Kindle
home » snippets » vim » syntax



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:

  1. 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.

  2. Match
    This is a match with a single regexp pattern.

  3. 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:

  1. When multiple Match or Region items start in the same position, the item
    defined last has priority.
  2. A Keyword has priority over Match and Region items.
  3. 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.