textmate-grammar

Use when creating or editing TextMate grammar files for VS Code syntax highlighting - patterns, scopes, and language tokenization

⭐5stars🔀1forks📁View on GitHub🕐Updated Jan 11, 2026

When & Why to Use This Skill

This Claude skill streamlines the creation and maintenance of TextMate grammar files, which are essential for VS Code syntax highlighting. It assists developers in defining complex regex patterns, managing hierarchical scopes, and organizing language tokenization rules, significantly reducing the manual effort required to build robust IDE support for new or existing programming languages.

Use Cases

  • Developing custom syntax highlighting for new programming languages or proprietary Domain Specific Languages (DSLs).
  • Debugging and refactoring existing TextMate grammar files to fix incorrect tokenization or scope assignments.
  • Mapping language-specific keywords and operators to standard VS Code scope naming conventions for better theme compatibility.
  • Implementing complex multi-line patterns and nested rule groups using the TextMate repository system for advanced language features.
nametextmate-grammar
descriptionUse when creating or editing TextMate grammar files for VS Code syntax highlighting - patterns, scopes, and language tokenization

TextMate Grammar

Quick Start

{
  "scopeName": "source.omg",
  "patterns": [{ "include": "#main" }],
  "repository": {
    "main": {
      "patterns": [
        { "include": "#comments" },
        { "include": "#strings" },
        { "include": "#keywords" }
      ]
    },
    "keywords": {
      "match": "\\b(if|else|while|return)\\b",
      "name": "keyword.control.omg"
    },
    "strings": {
      "begin": "\"",
      "end": "\"",
      "name": "string.quoted.double.omg",
      "patterns": [{ "include": "#escapes" }]
    }
  }
}

Core Concepts

  • scopeName: Unique identifier like source.js, text.html
  • patterns: Array of rules applied in order
  • repository: Named rule groups for reuse via #name
  • match: Single-line regex pattern
  • begin/end: Multi-line patterns with nested content

Scope Naming Conventions

Prefix Usage
keyword.control if, else, for, return
keyword.operator +, -, =, &&
storage.type class, function, var
entity.name.function function names
entity.name.type type/class names
variable.parameter function parameters
string.quoted quoted strings
comment.line single-line comments
constant.numeric numbers
punctuation.definition brackets, braces

Key Patterns

  • Use captures to assign scopes to regex groups: "captures": { "1": { "name": "..." } }
  • Use contentName for scope of content between begin/end
  • Escape backslashes in JSON: \\b for word boundary
  • Order matters: first matching pattern wins