Analyze the syntax of a document in CotEditor on Mac

CotEditor continuously analyzes the contents of your document and smartly supports text editing by visualizing structure with color, extracting an outline, and inserting comment delimiters according to each language’s grammar. These behaviors are organized as a “syntax” for each document type.

A syntax defines the behaviors of the following features:

Syntax highlighting

Syntax highlighting colors elements in a document according to predefined rules.

For example, in program source code, commands and variables can be color-coded according to their grammatical roles, making the structure of the code easier to understand. Syntax highlighting is also useful for structured formats like Markdown, or for drawing attention to characters or words that should not be used.

A syntax defines the semantic rules for highlighting, whereas a theme specifies the colors for highlighting.

Outline extraction

The Outline feature extracts specific parts of a document based on the syntax definition and generates a structured outline list. Some syntaxes produce a hierarchical outline that reflects nesting in the code, such as classes containing methods.

For instructions how to use the Outline feature, see Inspect the outline of a document.

Comment out

The Comment Out command intelligently inserts or removes the appropriate comment delimiters used by programming languages in the selected text. Comment-related commands are grouped in the Text > Comment menu.

Word completion

You can include syntax-specific reserved words to the completion list.

For details about the completion feature, see Complete a word.

Mode of the editor

A mode is a feature that lets you change the editor’s font and behavior in a unified way according to the type of document. The editor can switch its mode automatically based on the “kind” of the syntax applied to the document, or you can create individual mode settings for a syntax.

For details, see Switch editor modes.

CotEditor includes a wide range of built-in syntaxes for many major languages.

Set the syntax of a document

CotEditor automatically applies a syntax based on the document type. You can also set it manually from the Syntax menu in the toolbar or the Format menu.

Each syntax defines its own file-mapping rules. To learn how CotEditor determines which syntax to apply, see Map files to syntaxes.

Manage syntaxes

You can customize the built-in definitions or add your own. For details on editing syntaxes, see Define a syntax

See also