TextMate:条件格式?
我希望能够根据起始字符对线条进行不同的着色。
例如:
- This is line 1
- This is line 2
x This is line 3
- This is line 4
x This is line 5
因此第 1,2,4 行(以“-”开头)应为蓝色,而第 3,5 行(以“x”开头)应为红色。
这可能吗?你会怎么做?
谢谢。
I want to be able to color lines differently based on the starting character.
eg.:
- This is line 1
- This is line 2
x This is line 3
- This is line 4
x This is line 5
So lines 1,2,4 (starting with '-') should be blue while lines 3,5 (starting with 'x') should be red.
Is this possible? How would you do it?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过定义新语法来定义颜色。我的语法包含以下内容:
我创建了范围 text.todo 并将该语法分配给名为“foo.todo”的文件。
第一个模式表示“任意数量的空格,后跟破折号以及其后的任何内容”。这种匹配称为“常量”,因此 TextMate 将使用在“首选项”>“颜色”中为此范围定义的颜色。 “字体和颜色”。在我的主题中,常量是蓝色的。
第二种模式需要一个“x”而不是破折号,并调用匹配“variable.other.constant”,它在我的主题中恰好是红色的。您应该很容易从这里进行扩展。如果您需要帮助,只需按语法定义下方的问号即可。
You can define the color by defining a new grammar. My grammar contains the following:
I created the scope text.todo and assigned this grammar to an file which is named "foo.todo".
The first pattern says "any amount of whitespaces, followed by a dash and anything after it". This match is called "constant", thus TextMate will use the color which is defined for this scope in "Preferences" > "Fonts & Colors". Constants are blue in my theme.
The second pattern requires an "x" instead of a dash and calls the match "variable.other.constant", which happen to be red in my theme. It should be easy for you to extend from here. If you need help, just press the question mark below your grammar definition.