Define a syntax in CotEditor on Mac

Use the syntax editor in CotEditor to customize built-in syntaxes or create your own.

Open the syntax editor

  1. Go to the CotEditor app on your Mac.

  2. Choose CotEditor > Settings, then click Format.

  3. Do any of the following:
    • Customize an existing syntax: Select the syntax you want to customize in the “available syntaxes” list, then double-click the syntax name or click the Edit button.

    • Define a new syntax: Click the Add button below the “available syntaxes” list.

Your changes to a built-in syntax are saved as a user customization, and you can restore the original definition whenever needed.

Edit a syntax definition

In the syntax editor, you can configure the following aspects of a syntax definition:

Syntax parsing methods

CotEditor uses one of two content-parsing methods for syntax highlighting and outline extraction, depending on the syntax:

Parsing methodDescription
Regular-expression-based

This method uses keyword and regular-expression pattern matching. In this method, settings in the Delimiters pane are also used to highlight comments, strings, and characters. Because it is defined as a set of matching patterns rather than a full grammar, it is easy to define and customize.

Tree-sitter-based

Tree-sitter is a parser that builds a full syntax tree from source code. Because it understands a language's grammar, it can handle complex constructs such as deeply nested blocks, context-dependent keywords, and multi-line expressions more accurately than regular expressions alone.

Tree-sitter-based parsing is available for about 20 built-in syntaxes, including Swift, Python, JavaScript, HTML, and CSS. Because tree-sitter-based highlighting and outline rules are managed by the app, you cannot customize them or add tree-sitter support for additional syntaxes. By contrast, regular-expression-based syntaxes can be customized in the syntax editor: you can adjust the highlighting rules and outline extraction patterns for each syntax, or create entirely new syntax definitions from scratch.

Note: For performance reasons, the Markdown syntax uses tree-sitter only for outline extraction. Its syntax highlighting remains regular-expression-based.

Export a custom syntax

  1. Go to the CotEditor app on your Mac.

  2. Choose CotEditor > Settings, then click Format.

  3. Select the syntax to export in the “available syntaxes” list.

  4. Do one of the following:

    • Click the Action button or open the contextual menu for the selected item, then choose Export.

    • Click the Action button or open the contextual menu for the selected item, choose Share, then choose how to share it.

    • Drag the selected item into the Finder.

Note: Only custom syntaxes can be exported. Original built-in syntaxes can’t be exported.

Tip: You can export all custom syntaxes at once as a CotEditor Settings Archive. For details, see Export and import settings.

Import a custom syntax

  1. Go to the CotEditor app on your Mac.

  2. Choose CotEditor > Settings, then click Format.

  3. Do one of the following:

    • Click the Action button, choose Import, then choose a CotEditor syntax file (.cotsyntax format) to import.

    • Drag the CotEditor syntax file (.cotsyntax format) into the “available syntaxes” list.

A CotEditor syntax file is a package file with the .cotsyntax extension.

The Import command can also convert and import legacy YAML-based syntax definitions used before CotEditor 7.0.

See also