Home Explore Blog CI



neovim

1st chunk of `runtime/doc/usr_44.txt`
e04f6db2f3379d2433013caa26a1bc5b827514048bd8e3be0000000100000faa
*usr_44.txt*	Nvim

		     VIM USER MANUAL - by Bram Moolenaar

			 Your own syntax highlighted


Vim comes with highlighting for a couple of hundred different file types.  If
the file you are editing isn't included, read this chapter to find out how to
get this type of file highlighted.  Also see |:syn-define| in the reference
manual.

|44.1|	Basic syntax commands
|44.2|	Keywords
|44.3|	Matches
|44.4|	Regions
|44.5|	Nested items
|44.6|	Following groups
|44.7|	Other arguments
|44.8|	Clusters
|44.9|	Including another syntax file
|44.10|	Synchronizing
|44.11|	Installing a syntax file
|44.12|	Portable syntax file layout

     Next chapter: |usr_45.txt|  Select your language
 Previous chapter: |usr_43.txt|  Using filetypes
Table of contents: |usr_toc.txt|

==============================================================================
*44.1*	Basic syntax commands

Using an existing syntax file to start with will save you a lot of time.  Try
finding a syntax file in $VIMRUNTIME/syntax for a language that is similar.
These files will also show you the normal layout of a syntax file.  To
understand it, you need to read the following.

Let's start with the basic arguments.  Before we start defining any new
syntax, we need to clear out any old definitions: >

	:syntax clear

This isn't required in the final syntax file, but very useful when
experimenting.

There are more simplifications in this chapter.  If you are writing a syntax
file to be used by others, read all the way through the end to find out the
details.


LISTING DEFINED ITEMS

To check which syntax items are currently defined, use this command: >

	:syntax

You can use this to check which items have actually been defined.  Quite
useful when you are experimenting with a new syntax file.  It also shows the
colors used for each item, which helps to find out what is what.
   To list the items in a specific syntax group use: >

	:syntax list {group-name}

This also can be used to list clusters (explained in |44.8|).  Just include
the @ in the name.


MATCHING CASE

Some languages are not case sensitive, such as Pascal.  Others, such as C, are
case sensitive.  You need to tell which type you have with the following
commands: >
	:syntax case match
	:syntax case ignore

The "match" argument means that Vim will match the case of syntax elements.
Therefore, "int" differs from "Int" and "INT".  If the "ignore" argument is
used, the following are equivalent: "Procedure", "PROCEDURE" and "procedure".
   The ":syntax case" commands can appear anywhere in a syntax file and affect
the syntax definitions that follow.  In most cases, you have only one ":syntax
case" command in your syntax file; if you work with an unusual language that
contains both case-sensitive and non-case-sensitive elements, however, you can
scatter the ":syntax case" command throughout the file.

==============================================================================
*44.2*	Keywords

The most basic syntax elements are keywords.  To define a keyword, use the
following form: >

	:syntax keyword {group} {keyword} ...

The {group} is the name of a syntax group.  With the ":highlight" command you
can assign colors to a {group}.  The {keyword} argument is an actual keyword.
Here are a few examples: >

	:syntax keyword xType int long char
	:syntax keyword xStatement if then else endif

This example uses the group names "xType" and "xStatement".  By convention,
each group name is prefixed by the filetype for the language being defined.
This example defines syntax for the x language (eXample language without an
interesting name).  In a syntax file for "csh" scripts the name "cshType"
would be used.  Thus the prefix is equal to the value of 'filetype'.
   These commands cause the words "int", "long" and "char" to be highlighted
one way and the words "if", "then", "else" and "endif" to be highlighted
another way.  Now you need to connect the x group names to standard Vim
names.  You do this with the following commands: >

	:highlight

Title: User Manual: Your Own Syntax Highlighting
Summary
This section of the Vim user manual explains how to create syntax highlighting for file types not included in Vim's default settings. It covers basic syntax commands like `:syntax clear` and `:syntax`, matching case sensitivity with `:syntax case`, defining keywords using `:syntax keyword`, and highlighting syntax groups.