9

在 OSX 中,在 Sublime Text 3 (build 3065) 中,语法设置为JavaScript(JSX)或 just JSX,我按通常的 cmd+/来注释掉选定的文本。

//但是,当我想像这样包装选择时 ,ST3 默认为注释字符:

{/* foobar selected text */}

我在这里寻找,但无法弄清楚要编辑什么:

/Users/admin/Library/Application Support/Sublime Text 3/Packages/User/JavaScript (JSX).tmLanguage

提前致谢!:)

4

2 回答 2

8

创建一个包含以下内容的 XML 文件Packages/UserComments.tmPreferences我假设您的语言的基本范围是source.jsx- 您可以在.tmLanguage文件中找到它):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>name</key>
    <string>Comments</string>
    <key>scope</key>
    <string>source.jsx</string>
    <key>settings</key>
    <dict>
        <key>shellVariables</key>
        <array>
            <dict>
                <key>name</key>
                <string>TM_COMMENT_START</string>
                <key>value</key>
                <string>// </string>
            </dict>
            <dict>
                <key>name</key>
                <string>TM_COMMENT_START_2</string>
                <key>value</key>
                <string>{/* </string>
            </dict>
            <dict>
                <key>name</key>
                <string>TM_COMMENT_END_2</string>
                <key>value</key>
                <string> */}</string>
            </dict>
        </array>
    </dict>
    <key>uuid</key>
    <string>F9BFFF1F-1999-4722-B094-52E8AFD234D1</string>
</dict>
</plist>

//当您点击时将保持默认评论前缀⌘</kbd>/, but when you select some text and hit ⌘</kbd>Shift/ you will wrap it in {/* blahblahblah */}.

如果您想完全摆脱//,请改用以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>name</key>
    <string>Comments</string>
    <key>scope</key>
    <string>source.jsx</string>
    <key>settings</key>
    <dict>
        <key>shellVariables</key>
        <array>
            <dict>
                <key>name</key>
                <string>TM_COMMENT_START</string>
                <key>value</key>
                <string>{/* </string>
            </dict>
            <dict>
                <key>name</key>
                <string>TM_COMMENT_END</string>
                <key>value</key>
                <string> */}</string>
            </dict>
        </array>
    </dict>
    <key>uuid</key>
    <string>F9BFFF1F-1999-4722-B094-52E8AFD234D1</string>
</dict>
</plist>
于 2014-11-13T20:59:08.833 回答
0

虽然前面的答案部分解决了问题,但它并没有正确删除评论。

我向https://github.com/borela/naomi添加了一个插件,它可以正确检测要使用的所需评论类型,它适用于行和块评论。

于 2018-03-22T21:02:40.263 回答