使用 Sublime Text 2 的语法特定突出显示 [英] Syntax specific highlighting with Sublime Text 2

查看:25
本文介绍了使用 Sublime Text 2 的语法特定突出显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有办法在同一个文件中为不同的语言标签设置两种不同的标签颜色(美国的颜色").

I'm wondering if there is a way to have two different tag colours ("colors" for those in the US) for different language tags in the same file.

例如,假设我在同一个 .cfm 文件中有 ColdFusion 代码和 HTML 代码.我可以将 ColdFusion 标签设为红色,将 HTML 标签设为蓝色吗?

For example, lets say I have ColdFusion code and HTML code in the same .cfm file. Could I make the ColdFusion tags red and the HTML tags Blue?

例如,让我们调用下面的文件 HelloWorld.cfm - 我可以给标签涂上不同的颜色吗?

For instance, lets call the below file HelloWorld.cfm - could I colour the tags differently?

<cfset myvar = "hello, world" />
<html>
<head>
  <title>This is my title</title>
</head>
<body>

<div><cfoutput>#myvar#</cfoutput></div>

</body>
</html>

谢谢!

推荐答案

是的,只要标签可以被您安装的语言定义识别为具有不同的范围,您就可以编辑您的配色方案以针对具有特定颜色的范围和其他风格.

Yes, as long as the tags can be identified as having different scopes by your installed language definitions, you can edit your colour scheme to target those scopes with specific colours and other styles.

在您的包文件夹中,语言范围在 .tmLanguage 文件中为您安装的语言定义,而样式在color scheme - default"文件夹中的 .tmTheme 文件中定义.

In your packages folder, language scopes are defined in the .tmLanguage files for your installed languages, while styles are defined in the .tmTheme files in the "color scheme - default" folder.

如果您将光标置于标签内,然后按 shift+ctrl+alt+p (shift-cmd-p 在 OSX 我认为)状态栏将显示当前范围.您也可以使用以下命令通过控制台将其复制到剪贴板:

If you position your cursor inside a tag, and press shift+ctrl+alt+p (shift-cmd-p in OSX I think) the status bar will display the current scope. You can also copy this to the clipboard via the console with this command:

sublime.set_clipboard(view.syntax_name(view.sel()[0].b))

您可以使用此信息来创建样式,有点像 css 选择器,但使用 XML.例如,我使用这个 Coldfusion 包,并且在我的自定义 .tmTheme 文件中使用了如下所示的范围选择器来区分来自 HTML 标签的 cf 标签.

You can use this information to create your styles, a bit like css selectors, but with XML. For example I use this Coldfusion package and I have the scope selectors shown below in my custom .tmTheme file to distinguish cf tags from HTML tags.

<dict>
    <key>name</key>
    <string>Tag name</string>
    <key>scope</key>
    <string>entity.name.tag</string>
    <key>settings</key>
    <dict>
        <key>background</key>
        <string>#D8D0B6</string>
        <key>fontStyle</key>
        <string>bold</string>
        <key>foreground</key>
        <string>#647A4F</string>
    </dict>
</dict>
<dict>
    <key>name</key>
    <string>CF tag name</string>
    <key>scope</key>
    <string>entity.name.tag.conditional.cfml, entity.name.tag.declaration.cfml, entity.name.tag.other, entity.name.tag.cf, entity.name.tag.inline.other.cfml</string>
    <key>settings</key>
    <dict>
        <key>background</key>
        <string>#D8D0B6</string>
        <key>fontStyle</key>
        <string>bold</string>
        <key>foreground</key>
        <string>#990033</string>
    </dict>
</dict>

有关范围选择器的更多信息.

这篇关于使用 Sublime Text 2 的语法特定突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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