Sublime Forum

How to assign cmd + : to comment toggle?

#1

I can’t quite figure it out. I am new to Sublime and tried this :

{
“keys”: [“cmd+semicolon”],
“command”: “toggle_comment”
},

But that didn’t work. :disappointed:

0 Likes

#2

Here are some steps you can use to get this working the way you want it to:

  1. Select View > Show Console from the menu; a console pane will expand at the bottom of the window and the cursor will move to it’s input area.

  2. Enter the following two commands into the console, pressing enter after each one:

     sublime.log_commands(True)
     sublime.log_input(True)
    
  3. Press the key combination that you want to map (Cmd+;); the console will show you what key Sublime thinks this is:

     key evt: super+;
    
  4. Perform whatever command you want to bind the key to by pressing the currently bound key, or picking the appropriate menu or command palette entry (in your case that is Cmd+/ or Edit > Comment > Toggle Comment). The console will tell you what command and arguments it is executing:

     command: toggle_comment {"block": false}
    
  5. Execute the same commands in the console as in step #2, replacing True with False in order to turn the logging off (or restart Sublime when you’re done)

     sublime.log_input(False)
     sublime.log_commands(False)
    

Now you have all of the information that you need to generate the appropriate key binding:

{
    "keys": ["super+;"],
    "command": "toggle_comment",
    "args": {"block": false}
}
1 Like