neurd
neurd

Reputation: 3

How to create simple Sublime Text 3 custom syntax definition

I'm using Sublime Text build 3126 on a Windows machine, and I'm trying to follow the steps in this documentation for creating a very simple syntax definition file. Here is the example given:

%YAML 1.2
---
name: Z
file_extensions: z
scope: source.c

contexts:
  main:
    - match: \b(if|else|for|while)\b
      scope: keyword.control.c

This doesn't work for me in the same way as this post: no option for this custom definition appears under View > Syntax. The original poster seemed to resolve their issue, but I tried to uninstall and reinstall all of ST3 and related files, but I'm still having the same issue.

Upvotes: 0

Views: 498

Answers (1)

Keith Hall
Keith Hall

Reputation: 16065

There are two things to note here:

  1. The file extension must be .sublime-syntax for ST to treat it as a syntax definition. Using .yaml won't work.
  2. If you save the file in a folder that already contains a syntax definition, a submenu will be created with the name of the folder, and the syntax will be under that. i.e. if you have one syntax definition in Packages/User/, and then save another one, both of them will then appear under the User submenu instead of the main syntax list i.e. View -> Syntax -> User -> Z. Note that you can also use the command palette to find a syntax definition by typing Set Syntax:

Upvotes: 1

Related Questions