vi

format of vi syntax configuration and map files 

File Format


DESCRIPTION

To properly handle syntax highlighting, vi and viw use syntax configuration files that describe how the syntax for a given programming, scripting, or mark-up language should be highlighted. While several syntax configuration files are included with MKS Toolkit, you can also create new configuration files to handle additional languages.

These configuration files must have a .viw extension. When the vi option variable syntaxlanguage is set to DETECT, vi searches for the appropriate syntax configuration file to use. This file will be of the form ext.viw where ext is the file extension of the file being edited. vi first looks for this file in the $HOME/syntax directory and, if not found, in the $ROOTDIR/etc/syntax directory.

When you install MKS Toolkit, a number of syntax configuration files are installed in $ROOTDIR/etc/syntax. To determine which syntax configuration file should be used to highlight which file name. vi use syntax map files as described in the Syntax Map Files section.

General Structure

Syntax configuration files are flat text files. They contain five types of lines:

A line beginning with # is a comment lines and is ignored by vi. Blank lines are also ignored.

A line beginning with syntaxGroup defines a syntax group and specifies which commands, key words, strings, and blocks are assigned to that group. For instance, in a syntax configuration file for the C programming language, the key words if and while might be assigned to a syntax group named cConditional while the keywords int and char might be assigned to one named cDatatype. Similarly, a string beginning with // might be assigned to lineComment, a block that starts with /* and ends with */ might be assigned to blockComment, and some strings beginning with # (such as #include) might be assigned to cPreProcessor.

A line beginning with hilightGroup defines a mapping of syntax groups to a highlight group. The highlight group defines color is used to displayed members of the mapped syntax group. Continuing with the C language example, the cConditional, cDatatype, and cPreprocessor syntax groups might be mapped to the Keyword highlight group, while the lineComment and blockComment syntax groups might be mapped to the Comment highlight group.

Lines that specify the value of a boolean flag can change the behavior of the pattern matching used by the syntaxGroup statements.

syntaxGroup Statement

A syntaxGroup statement has one of the following formats:

syntaxGroup	syntax_group_name	keyword_list

syntaxGroup	syntax_group_name	startStr="start_string"	endStr="end_string"

syntaxGroup	syntax_group_name	startStr="start_string"	endStr="EOLPAT"

syntaxGroup	syntax_group_name	startStr="start_string"	keyword_list

The individual elements of these formats are defined as follows:

hilightGroup Statement

The hilightGroup statement has the following format:

hilightGroup	highlight_group_name		syntax_group_name_list

The individual elements formats are defined as follows:

Boolean Flags

The format for setting a boolean flag is:

boolean_flag=value

where boolean_flag is the name of the flag to be set and value is either 0 or 1.

The following boolean flags are currently supported:

match_case 

When set to 1, syntax patterns are case sensitive. When set to 0, they are case insensitive. By default, syntax patterns are case insensitive.

highlight_inside_quotes 

When set to 1, syntax highlighting occurs inside of double quotes. When set to 0, double quotes do not allow highlighting inside of them. By default, syntax highlighting does not occur within double quotes.

backslash_continues_strings 

When set to 1, syntax highlighting works like the C language where multiline string constants must be continued by appending a \ at the end of the line. When set to 0, it works like shell scripts where strings continue without \. For example:

echo "starting
and
continuing"

By default, syntax highlighting works like C.

Example

The following is an excerpt from the c.viw provided with MKS Toolkit:

# Comments 
syntaxGroup		cComment1		startStr="/*"	endStr="*/" 
syntaxGroup		cComment2		startStr="//"	endStr="EOLPAT"

# Preprocessor keywords start with  #
syntaxGroup		cPreProc1		startStr="#"	if ifdef endif else elif define undef ifndef 

# Keywords used in conditional or iterative statements
syntaxGroup		cCond		break case continue do else if switch while 

# Keywords for datatypes
syntaxGroup		cType1		bool char class double enum float int long short
syntaxGroup		cType2		signed struct typedef union unsigned void wchar_t

# Known Constants
syntaxGroup		cConst		NULL TRUE FALSE

# Keywords or strings used for operators.
syntaxGroup		cplusOper1	and and_eq bitand bitor const_cast dynamic_cast 
syntaxGroup		cplusOper2	not not_eq operator or or_eq xor xor_eq
syntaxGroup		cplusOper3	sizeof static_cast reinterpret_cast 

syntaxGroup		cOtherKey1	asm auto catch delete explicit 
syntaxGroup		cOtherKey1	export extern false friend goto inline mutable 
syntaxGroup		cOtherKey2	namespace new private protected public pure 
syntaxGroup		cOtherKey2	register return static template 
syntaxGroup		cOtherKey3	this throw true try typeid typename using 
syntaxGroup		cOtherKey3	virtual volatile const

# Map syntax groups to hilight groups. 

hilightGroup		Conditional	cCond
hilightGroup		Keyword		cOtherKey1 cOtherKey2 cOtherKey3 
hilightGroup		PreProc		cPreProc1 cPreProc2
hilightGroup		Comment		cComment1 cComment2
hilightGroup		Type		cType1 cType2
hilightGroup		Operator		cplusOper1 cplusOper2 cplusOper3
hilightGroup		Const		cConst

Syntax Map Files

As mentioned earlier, vi uses syntax map files to associate extensions and file names with syntax configuration files. The provided $ROOTDIR/etc/syntax/syntax.map file includes mappings for several common extensions and file names:

File or Extension                 File
.c, .h, .cc, .cpp, .hpp           c.viw
.i                                asm.viw
.bat, .cmd                        bat.viw
.jav, .java                       java.viw
.htm, .html, .sgm, .sgml, .xml    html.viw
.jj, .jjt                         javacc.viw
.csh                              csh.viw
.sh, .ksh                         sh.viw
.pl                               perl.viw
.php                              php.viw
.mk                               make.viw
makefile                          make.viw
.profile                          sh.viw

If you change or replace any of the listed files or place a file of the same name in your $HOME/syntax directory, that file is used instead.

You can override the associations given in the $ROOTDIR/etc/syntax/syntax.map file by creating a $HOME/syntax/syntax.map file. This file consists of a list of regular expressions and associated syntax configuration files. Each entry consists of a regular expression followed by white space and the name of the associated syntax configuration file. For example, a $HOME/syntax/syntax.map map containing:

.*[.]cpp		cpp.viw
.*[.]tst		test.viw

indicates that syntax highlighting for files with a .cpp extension should use cpp.viw instead of the normal c.viw. Similarly, it adds a new association for files with a .tst extension. These files will use the test.viw syntax file to determine syntax highlighting.


AVAILABILITY

PTC MKS Toolkit for System Administrators
PTC MKS Toolkit for Developers
PTC MKS Toolkit for Interoperability
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Commands:
vi, viw, viw_vs


PTC MKS Toolkit 10.1 Documentation Build 15.