Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define comment characters for React JSX in Sublime Text?

In OSX, in Sublime Text 3 (build 3065), with syntax set as JavaScript(JSX) or just JSX, I'm hitting the usual cmd+/ to comment out the selected text.

However, ST3 is defaulting to the // comment chars, when I want to wrap selection like this:

{/* foobar selected text */}

I'm looking in here, but can't figure out what to edit:

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

Thanks in advance! :)

like image 476
Rowe Morehouse Avatar asked Nov 11 '14 20:11

Rowe Morehouse


People also ask

How do I comment code in React JSX?

Syntax. JSX comments begin and end with curly braces {} . Followed by the opening curly brace is a forward slash and an asterisk. After that is the comment and lastly, an asterisk, a forward slash and the closing curly brace.

Can I use Sublime Text for React?

In order to install it, go to Sublime Text and open the console by pressing (ctrl + `) (regardless if you are on Windows, Linux or OS X), or go to View > Show Console then (update: 06/07/18) go to the official installation page, and copy the Sublime Text 3 version of the code, then paste it into the Sublime Text ...


1 Answers

Create an XML file in Packages/User called Comments.tmPreferences with the following contents (I'm assuming the base scope of your language is source.jsx - you can find this in the .tmLanguage file):

<?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>

// will remain the default comment prefix when you hit /, but when you select some text and hit Shift/ you will wrap it in {/* blahblahblah */}.

If you want to completely get rid of //, use the following instead:

<?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>
like image 74
MattDMo Avatar answered Oct 02 '22 04:10

MattDMo