Search code examples
sublimetext2key-bindings

Can SublimeText2 key bindings map to package commands, like "SublimeREPL:Ruby"?


I'm trying to create a key binding for opening a SublimeREPL:Ruby window in ST2, but am not sure if you can create shortcuts for non-basic commands.

I've searched around http://sublimetext.info/docs/en/reference/key_bindings.html and googled my little heart out but can't find anything about creating key bindings for foreign packages.

On 2nd thought (I'm a 1y/o dev) - I decided to browse package files. I found this in /Users/administrator/Library/Application Support/Sublime Text 2/Packages/SublimeREPL/config/Ruby:

[
 {
    "id": "tools",
    "children":
    [{
        "caption": "SublimeREPL",
        "mnemonic": "r",
        "id": "SublimeREPL",
        "children":
        [
            {"command": "repl_open", 
             "caption": "Ruby",
             "id": "repl_ruby",
             "mnemonic": "r",
             "args": {
                "type": "subprocess",
                "external_id": "ruby",
                "encoding": "utf8",
                "cmd": {"windows": ["irb.bat", "--noreadline", "--inf-ruby-mode"],
                        "linux": ["irb", "--noreadline", "--inf-ruby-mode"],
                        "osx": ["irb", "--noreadline", "--inf-ruby-mode"]},
                "soft_quit": "\nexit\n",
                "cwd": "$file_path",
                "cmd_postfix": "\n", // postfix 
                "suppress_echo": true,
                "syntax": "Packages/Ruby/Ruby.tmLanguage"
                }
            }
        ]   
    }]
}
]

I created the key binding:{ "keys": ["super+i", "super+r", "super+b"], "command": "repl_open" }

But no dice. Any ideas? Restart ST2 maybe?


Solution

  • When you define the shortcut key, you should supply the repl_open command the arguments it got in the declaration of the menu item you provided.

    Try the following (not tested, but very similar to the configuration I have for another environment in REPL):

    { "keys": ["super+i", "super+r", "super+b"], "command": "repl_open", "args":
       {
            "type": "subprocess",
            "external_id": "ruby",
            "encoding": "utf8",
            "cmd": {"windows": ["irb.bat", "--noreadline", "--inf-ruby-mode"],
                "linux": ["irb", "--noreadline", "--inf-ruby-mode"],
                "osx": ["irb", "--noreadline", "--inf-ruby-mode"]},
            "soft_quit": "\nexit\n",
            "cwd": "$file_path",
            "cmd_postfix": "\n", // postfix 
            "suppress_echo": true,
            "syntax": "Packages/Ruby/Ruby.tmLanguage"
       }
    }
    

    A simpler option (but less configurable) is just to call the menu item directly (again, not tested but similar to my configuration):

    { "keys": ["super+i", "super+r", "super+b"],
      "command": "run_existing_window_command", "args":
        {
            "id": "repl_ruby",
            "file": "config/Ruby/Main.sublime-menu"
        }
    },