跟进 ig0774 的 answer,以下是一些具体的操作示例。首先,使用 YAML 语法和以下内容在 Sublime 中创建一个新文件:
%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: ToDo Manager
file_extensions:
- todo
scope: text.todo
contexts:
main:
- match: (?i)\btest\b
scope: meta.test
- match: (?i)\bstackoverflow\b
scope: meta.stackoverflow
- match: (?i)\bexample\b
scope: meta.example
您可以将name 更改为您想要的任何内容,并为您的文件修改file_extensions。然后,将文件保存在您的Packages/User 文件夹(可以通过选择Preferences -> Browse Packages... 找到)中为ToDo Manager.sublime-syntax。
现在是配色方案。我们在这里假设您使用的是默认的 Monokai 配色方案。实际的.tmTheme 文件包含在.sublime-package 存档中,因此要访问它,您需要安装PackageResourceViewer 插件。安装后,打开命令面板并输入 prv 以调出 PackageResourceViewer 选项。选择Edit Package Resource,导航到Color Scheme - Default,然后向下滚动并选择Monokai.tmTheme。如果您使用的是其他默认配色方案,请改为选择该文件。如果您安装了配色方案,请先打开该软件包,然后选择相应的 .tmTheme 文件。
如果 .tmTheme 文件没有语法高亮,请选择 XML。接下来,向下滚动到最后。最后 5 行应如下所示:
</array>
<key>uuid</key>
<string>06CD1FB2-A00A-4F8C-97B2-60E131912345</string>
</dict>
</plist>
虽然uuid 可能会有所不同。在</array> 行之前插入以下内容:
<dict>
<key>name</key>
<string>test</string>
<key>scope</key>
<string>meta.test</string>
<key>settings</key>
<dict>
<key>background</key>
<string></string>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#FF8000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>stackoverflow</string>
<key>scope</key>
<string>meta.stackoverflow</string>
<key>settings</key>
<dict>
<key>background</key>
<string></string>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#0FD7FF</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>example</string>
<key>scope</key>
<string>meta.example</string>
<key>settings</key>
<dict>
<key>background</key>
<string></string>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#FF0000</string>
</dict>
</dict>
现在,选择File -> Save,它将被保存在正确的位置,覆盖.sublime-package 中的文件。最后,打开一个.todo 文件并选择View -> Syntax -> Open all with current extension as... -> User -> ToDo Manager,您应该会看到类似这样的突出显示: