How to create a keyboard shortcut for SublimeREPL
Asked Answered
L

6

21

I am new to Sublime Text 2 on Mac OS. I installed the package SublimeREPL.

Is it possible to create a keyboard shortcut to run the file with SublimeREPL?

More precisely, here is a screenshot. I want to avoid going through this menu and run quickly with a keyboard shortcut.

enter image description here

Label answered 4/10, 2013 at 13:7 Comment(0)
C
11

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.

Carothers answered 4/10, 2013 at 13:20 Comment(0)
R
74

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)

screenshot

Romanticist answered 14/11, 2013 at 12:5 Comment(3)
Very helpful answer. Solved it for me on Linux and saved from a giant pain!Thickset
Works fine on Mac OS X as well. Thanks a bunch!Mainly
Works on Sublime 3, Windows 10 as well.Gotthelf
C
11

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.

Carothers answered 4/10, 2013 at 13:20 Comment(0)
F
3

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"
}}
]
Frieze answered 15/3, 2019 at 4:40 Comment(1)
Thanks for this . Working on W10 and Sublime3.2 .Larhondalari
G
1

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"
            }
}]
Goar answered 15/3, 2019 at 17:58 Comment(0)
M
1

i have an addition to Romina's answer, i used her code, but it opens with Python default version, in my case (Linux Mint) it was Python 2.7, so if you have that trouble just change her code with this:

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

And it works with Python 3 (if you have it installed of course)

Moulden answered 29/3, 2019 at 20:3 Comment(0)
L
0

tq, add debug

{ "keys": ["ctrl+b"], "command": "run_existing_window_command", "args":
        {
        "id": "repl_python_pdb",
        "file": "config/Python/Main.sublime-menu"
        }
},
Longplaying answered 18/3, 2016 at 15:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.