Sublime Text 2 中的自定义语法高亮 [英] Custom syntax highlighting in Sublime Text 2

查看:70
本文介绍了Sublime Text 2 中的自定义语法高亮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Sublime Text 作为日志查看器.这就是为什么我需要创建 tmlanguage 文件来突出显示单词ERROR"(以及其他一些).是否有任何 tmlanguage xml 规范,或者您能给我一个 sublime text 2 的语法高亮文件的基本示例吗?

I want to use Sublime Text as log viewer. That's why I need to create tmlanguage file for highlighting of word "ERROR" (and some others). Is there any spec of tmlanguage xml, or can you give me basic example of syntax-highlighting file for sublime text 2?

我没有在类似问题中找到答案:语法特定的突出显示使用 Sublime Text 2

I've not found the answer in a similar question: Syntax specific highlighting with Sublime Text 2

推荐答案

Sublime Text 使用与 TextMate 相同的语法高亮.可以在此处找到语法.我建议使用 JSON 然后转换为 XML,因为它更容易阅读(至少对我来说).PackageDev 插件将为您提供定义新语法的起始片段.它还包含一些用于配置的语法突出显示,以及 Plist 到 JSON 转换器.下面是一个 protobuf 语法定义文件的片段,它突出显示了特定的单词.至于高光的颜色,您必须查看您的配色方案文件.在下面的示例中,您将查找它使用的颜色的范围constant.language".您可能不需要编辑配色方案,除非您想要的不是已经内置到您的方案中的内容.

Sublime Text uses the same syntax highlighting as TextMate. The grammar can be found here. I'd recommend working in JSON then converting to XML, since it's easier (at least it is for me) to read. The PackageDev plugin will give you a starting snippet for defining a new syntax. It also contains some syntax highlighting for configurations, as well as a Plist to JSON converter. Below is a snippet from a protobuf syntax definition file that highlights specific words. As for the colors of the highlights, you will have to look through your color scheme file. In the below example, you would look for the scope "constant.language" for the color it uses. You probably don't need to edit the color scheme, unless you want something other than what is already built into your scheme.

{ 
    "name": "Protocol Buffers",
    "scopeName": "source.proto",
    "fileTypes": ["proto"],
    "patterns": [{
            "match": "\\b(bool|bytes|double|fixed32|fixed64|float|int32|int64|sfixed32|sfixed64|sint32|sint64|string|uint32|uint64)\\b",
            "name": "constant.language.proto"
    }],
    "uuid": "8c8714d5-43ef-43d2-abd9-c9088901ddd5"
}

这篇关于Sublime Text 2 中的自定义语法高亮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆