How to create a keyboard shortcut for SublimeREPL

You can set a keyboard shortcut for the command in your screenshot using Sublime key-bindings.

  1. Open Sublime.

  2. Go to Preferences > Key Bindings - User

  3. Add these lines to the opened file between brackets:

    { "keys": ["ctrl+alt+b"], "command": "run_existing_window_command", "args":
    {
        "id": "repl_python_run",
        "file": "config/Python/Main.sublime-menu"
    }}
    
  4. Save it.

It's done! You can type any key-combinations instead of "ctrl+alt+b", but make sure it's not reserved by Sublime itself (check in Preferences > Key Bindings - Default)

Note: This works for Sublime in Windows. I don't think there would be any difference for Sublime on Mac OS/Linux.

screenshot


I found that I lost the keybinding to the installed sublimeREPL, so I had to find how to get it back, since it is a time saving indispensable for me. I used it also on a pc that had not sublime Repl and worked for both. This worked for me in 2019, version 3.2

in preferences / keybinding (after you installed package control and sublimeREPL). I made this video too.

[

{"keys": ["ctrl+b"], "command": "repl_open",
 "caption": "Python - RUN current file",
 "id": "repl_python_run",
 "mnemonic": "d",
 "args": {
    "type": "subprocess",
    "encoding": "utf8",
    "cmd": ["C:/Users/giova/AppData/Local/Programs/Python/Python37-32/python.exe", "-u", "-i", "$file_basename"],
    "cwd": "$file_path",
    "syntax": "Packages/Python/Python.tmLanguage",
    "external_id": "python",
    "extend_env": {"PYTHONIOENCODING": "utf-8"}
        }}
]

p.s.: change the location of the python.exe as it is stored in your pc.

You can also do this:

[

{"keys": ["ctrl+b"], "command": "repl_open",
 "caption": "Python - RUN current file",
 "id": "repl_python_run",
 "mnemonic": "s",
 "args": {
    "extend_env": {"PYTHONIOENCODING": "utf-8"},
    "cmd": ["py", "-u", "-i", "$file_basename",],
    "type": "subprocess",
    "encoding": "utf8",
    "cwd": "$file_path",
    "syntax": "Packages/Python/Python.tmLanguage",
    "external_id": "python",
    "view_id": "*REPL* [python]",
        }}
]

To use different version of python, you can type py -2.7 for example, if you have them installed. You can also use 'python' in the cmd list. To see where the location of python is, you can import sys and look at sys.path from python itself. You can also add "-m", "-pdb" to do the debugging, using another key combination maybe.

This works again in 3.2

[
{ "keys": ["ctrl+b"], "command": "run_existing_window_command", "args":
{
    "id": "repl_python_run",
    "file": "config/Python/Main.sublime-menu"
}}
]

You can set keyboard shortcuts for any menu item that you can select, in any app.

  1. Go to System PreferencesKeyboardShortcutsApp Shortcuts

  2. Click the + to add a new shortcut.

  3. Set the Application to Sublime Text.app, the Menu Title to the exact name of the menu option, and choose a Keyboard Shortcut.

  4. Click Add.


Go to Preferences -> Key Bindings, and write this in the window "Sublime-keymap --User"

[
{
    "keys": ["ctrl+alt+b"],
    "command": "repl_open",
    "args": {
                "cmd": ["python", "-u", "-i", "$file_basename"],
                "cwd": "$file_path",
                "encoding": "utf8",
                "extend_env": {"PYTHONIOENCODING": "utf-8"},
                "external_id": "python",
                "syntax": "Packages/Python/Python.tmLanguage",
                "type": "subprocess"
            }
}]