【问题标题】:Sublime Text Editor 3 - Theme-ing - Change docstring colorSublime Text Editor 3 - Theme-ing - 更改文档字符串颜色
【发布时间】:2014-03-06 02:30:48
【问题描述】:

我正在使用用于 Linux 的 sublime 文本编辑器 3。我正在使用它来编写 Python 代码。我希望能够将文档字符串的颜色更改为另一种颜色,而无需更改常规注释的颜色 (#)。我查看了.tmTheme 文件,但在其中找不到关于文档字符串颜色的任何信息。然而,有一个主题显然有两种不同颜色的文档字符串和常规注释。

如何修改主题,使文档字符串和注释成为两种不同的颜色?

【问题讨论】:

    标签: python themes sublimetext sublimetext3


    【解决方案1】:

    如果您想修改其中一种默认配色方案,您应该按照StackOverflow 上的关于安装 PackageResourceViewer 的答案进行操作,这将允许您打开默认配色方案并对其进行编辑。安装 PackageResourceViewer 后,只需按 ⌘+Shift+P 并搜索 PackageResourceViewer:Open Resource → Color Scheme - Default → THEME,其中 THEME 是您要编辑的主题。这将打开一个.tmTheme 文件,其中包含该主题的所有当前设置。如果要更改任何特定于语言的语法突出显示,则需要知道 sublime-syntax 文件调用要更改的语法的名称。 syntax definition files for Sublime Text 托管在 GitHub 上,并显示使用哪个正则表达式来定义该语言的各种语法。要更改 Python 语言文档字符串,我们可以查看 Python.sublime-syntax 文件,其中显示 meta_scope: comment.block.documentation.python。这意味着我们需要使用comment.block.documentation.python 作为.tmTheme 文件中设置的范围,我们可以给它任何我们想要的设置。因此,要更改文档字符串,应将此文本块添加到您的 .tmTheme 文件中:

    <dict>
        <key>name</key>
        <string>Python-Docstring</string>
        <key>scope</key>
        <string>comment.block.documentation.python</string>
        <key>settings</key>
        <dict>
            <key>foreground</key>
            <string>#FFFFFF</string>
        </dict>
    </dict>
    

    我们将此样式更改的名称指定为 Python-Docstring(Sublime Text 忽略此字段),我们通过将范围设置为 comment.block.documentation.python 来告诉它我们将在 python 中使用文档字符串的语法突出显示,我们正在更改该范围内的设置以使前景文本#FFFFFF。我建议将此文件保存在/Users/USERNAME/Library/Application Support/Sublime Text 3/Packages/User 中,以便将来更容易访问并且不会覆盖默认主题。最后在 Sublime Text 中你去Sublime Text → Preferences → Color Scheme 并选择你的主题!

    【讨论】:

      【解决方案2】:

      我知道这个帖子很旧,但我遇到了同样的问题,无法更改颜色。所以这就是它对我的工作方式,我希望它会对某人有所帮助。这些是我通过资源查看器放置的行:

      <dict>
              <key>name</key>
              <string>docstring</string>
              <key>scope</key>
              <string>string.quoted.double.block, comment.block.documentation, string.quoted.single.block</string>
              <key>settings</key>
              <dict>
                  <key>fontStyle</key>
                  <string>italic</string>
                  <key>foreground</key>
                  <string>#03FFA7</string>
              </dict>
          </dict>
      
      <dict>
              <key>name</key>
              <string>String Quotes</string>
              <key>scope</key>
              <string>comment.block.documentation punctuation.definition.comment.begin, comment.block.documentation punctuation.definition.comment.end,
                      ,string.quoted punctuation.definition.string.begin, string.quoted punctuation.definition.string.end</string>
              <key>settings</key>
              <dict>
                  <key>fontStyle</key>
                  <string>italic</string>
                  <key>foreground</key>
                  <string>#1FFF0F</string>
              </dict>
          </dict>
      

      【讨论】:

        【解决方案3】:

        我发现 this answer 基本上建议您更改 tmTheme 中的条目:在 Comment 定义中,添加 python 文档字符串。

            <dict>
                <key>name</key>
                <string>Comment</string>
                <key>scope</key>
                <string>comment, string.quoted.double.block.python</string>
                <key>settings</key>
                <dict>
                    <key>foreground</key>
                    <string>#757575</string>
                </dict>
            </dict>
        

        要轻松更改您的 tmTheme,PackageResourceViewer(在this question 中接受的答案中提到)效果很好。

        这会将您的文档字符串更改为与注释相同的颜色。我还没有测试过这个,但我假设做出一个新的定义,比如

            <dict>
                <key>name</key>
                <string>Python-Docstring</string>
                <key>scope</key>
                <string>string.quoted.double.block.python</string>
                <key>settings</key>
                <dict>
                    <key>foreground</key>
                    <string>#FFFFFF</string>
                </dict>
            </dict>
        

        将允许您指定一种新颜色。

        【讨论】:

          【解决方案4】:

          我开发了Neon Color SchemePython Improved 语言定义,专门用于使Python 和尽可能多的其他语言看起来尽可能好,并具有尽可能多的范围。它还包括 docstrings 和 cmets 的不同颜色:

          以下是.tmTheme 文件中用于文档字符串的条目:

          <dict>
              <key>name</key>
              <string>docstring</string>
              <key>scope</key>
              <string>string.quoted.double.block, string.docstring, string.quoted.single.block</string>
              <key>settings</key>
              <dict>
                  <key>fontStyle</key>
                  <string>italic</string>
                  <key>foreground</key>
                  <string>#218B97</string>
              </dict>
          </dict>
          

          和常规的 cmets:

          <dict>
              <key>name</key>
              <string>Comment</string>
              <key>scope</key>
              <string>comment</string>
              <key>settings</key>
              <dict>
                  <key>fontStyle</key>
                  <string>italic</string>
                  <key>foreground</key>
                  <string>#7F817E</string>
              </dict>
          </dict>
          

          而且,如果你想让你的引号脱颖而出:

          <dict>
              <key>name</key>
              <string>String Quotes</string>
              <key>scope</key>
              <string>string.quoted punctuation.definition.string.begin, string.quoted punctuation.definition.string.end</string>
              <key>settings</key>
              <dict>
                  <key>fontStyle</key>
                  <string>italic</string>
                  <key>foreground</key>
                  <string>#FF07A2</string>
              </dict>
          </dict>
          

          【讨论】:

          • 我喜欢你定义了很多范围,但是 NEON 配色方案太暗了。我还能从您的范围定义中受益吗?
          猜你喜欢
          • 1970-01-01
          • 2014-06-15
          • 2013-07-23
          • 2018-09-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-02-14
          • 1970-01-01
          相关资源
          最近更新 更多