Comments in python don’t work after sublime upgrade to 3103
Question: I just upgraded to Sublime 3103, and now the comment shortcut `command+/` does
not work. This is weird because it doesn't work only in Python. For all other
programming languages, it works just fine.

I tried setting up a custom keybinding for comments, and again the same
problem. Works everywhere else, except in python.

What could be the problem?


Answer: I also cannot reproduce this, but here is a way to fix it. Go to
**`Preferences → Browse Packages…`** to open the `Packages` folder in your
operating system's file manager. Create a new folder named `Python`, and
inside that new folder create an empty file named `Comments.tmPreferences`
(capitalization is important). Next, open the new file in Sublime with XML
syntax highlighting and add the following contents:

    
    
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//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.python</string>
        <key>settings</key>
        <dict>
            <key>shellVariables</key>
            <array>
                <dict>
                    <key>name</key>
                    <string>TM_COMMENT_START</string>
                    <key>value</key>
                    <string># </string>
                </dict>
            </array>
        </dict>
        <key>uuid</key>
        <string>6550FEAD-D547-44E4-84F7-7D421D6078B0</string>
    </dict>
    </plist>
    

Save the file, and it should take effect immediately.

* * *

This works by explicitly telling Sublime to use a certain pattern for
comments. The `.tmPreferences` extension came from
[TextMate](http://macromates.com), a pretty good editor for OS X that Jon
Skinner used as one of his inspirations (along with `vi`) when writing
Sublime. (BTW, if you're on OS X, check out TextMate 2 - it's open-source, and
has a lot of neat features. A much smaller plugin community, though...)

As you can see, the file is XML-based, and defines a `shellVariable` named
`TM_COMMENT_START` (again, the `TM` is from TextMate) which is used internally
to demarcate a single-line comment. Depending on the `scope` value, a
`Comments.tmPreferences` file can be used for any language you wish. If your
programming language also has a block comment construct, as well as a single-
line comment, you can define that with `TM_COMMENT_START_2` and
`TM_COMMENT_END_2` like so:

    
    
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//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.python</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>6550FEAD-D547-44E4-84F7-7D421D6078B0</string>
    </dict>
    </plist>
    

Here, we're still in Python, but we're using triple quotes to define a block
comment or docstring. Simply highlight the region you want to surround with
triple quotes and hit `⌘``Shift``/` (`Ctrl``Shift``/` on Windows/Linux).

