# How to map a key to SublimeREPL command?

**URL:** <https://forum.sublimetext.com/t/how-to-map-a-key-to-sublimerepl-command/26569>\
**Category:** Technical Support\
**Created:** [March 8, 2017, 3:15pm UTC](https://forum.sublimetext.com/t/how-to-map-a-key-to-sublimerepl-command/26569 "2017-03-08T15:15:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zBernie](https://forum.sublimetext.com/letter_avatar_proxy/v4/letter/z/edb3f5/32.png) [@zBernie](https://forum.sublimetext.com/u/zBernie)\
**Post date:** [March 8, 2017, 3:15pm UTC](https://forum.sublimetext.com/t/how-to-map-a-key-to-sublimerepl-command/26569/1 "2017-03-08T15:15:53Z")

</div>

I’d like to map the following SublimeREPL plugin menu command to a key so I can easily execute it:

Tools -\> SublimeREPL -\> Python -\> Python - Run current file

I used the package resource viewer and looked at the key mappings for SublimeREPL, but don’t so how to accomplish this.

-Thanks

---

<div class="post-metadata">

**Author:** ![botoggle](https://forum.sublimetext.com/user_avatar/forum.sublimetext.com/botoggle/32/51710_2.png) [@botoggle](https://forum.sublimetext.com/u/botoggle)\
**Post date:** [March 9, 2017, 1:07pm UTC](https://forum.sublimetext.com/t/how-to-map-a-key-to-sublimerepl-command/26569/2 "2017-03-09T13:07:17Z")

</div>

SublimeREPL is supposed to have a default binding for “open the current file in a REPL,” I think it’s ctrl+, then f, but if that doesn’t work for some reason, you could try adding this to your regular Sublime Key Configuration file:

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

```

(Adjust the binding to your taste.)

SublimeREPL has a fairly complicated command structure; this is taken from the `SublimeREPL/config/Python/Default.sublime-commands` file, and runs a command defined in `Main.sublime-menu` in the same directory. There might be a better way to do this, but this worked for me just now.

---

<div class="post-metadata">

**Author:** ![zBernie](https://forum.sublimetext.com/letter_avatar_proxy/v4/letter/z/edb3f5/32.png) [@zBernie](https://forum.sublimetext.com/u/zBernie)\
**Post date:** [March 10, 2017, 5:58am UTC](https://forum.sublimetext.com/t/how-to-map-a-key-to-sublimerepl-command/26569/3 "2017-03-10T05:58:37Z")

</div>

When I type ctrl+, f, I get the following error message:

“Cannot find REPL for ‘python’”

But if I select from the menu:

Tools -\> SublimeREPL -\> Python -\> Python - Run current file

It works. Any idea why the key binding produce the error?

-Thanks

---

<div class="post-metadata">

**Author:** ![OdatNurd](https://forum.sublimetext.com/user_avatar/forum.sublimetext.com/odatnurd/32/77607_2.png) [@OdatNurd](https://forum.sublimetext.com/u/OdatNurd)\
**Post date:** [March 10, 2017, 6:10am UTC](https://forum.sublimetext.com/t/how-to-map-a-key-to-sublimerepl-command/26569/4 "2017-03-10T06:10:11Z")

</div>

I don’t use that particular plugin, but if you open the Sublime console with Ctrl+` or `View > Show Console`, you can enter the command:

```auto
sublime.log_commands(True)

```

That tells Sublime to log all commands as it’s executing them. Running the command via the key binding and via the menu may point out what one of them is doing differently than the other and help you trace why it doesn’t work.

You can run the same command with `False` instead to turn off command logging when you’re done (or restart Sublime).

---

<div class="post-metadata">

**Author:** ![zBernie](https://forum.sublimetext.com/letter_avatar_proxy/v4/letter/z/edb3f5/32.png) [@zBernie](https://forum.sublimetext.com/u/zBernie)\
**Post date:** [March 10, 2017, 6:37am UTC](https://forum.sublimetext.com/t/how-to-map-a-key-to-sublimerepl-command/26569/5 "2017-03-10T06:37:07Z")

</div>

Thanks, very useful to know. I get “The handle is invalid” error below. Not sure how to fix it though. I read the docs and run repl from the command console to enable a SublimeREPL:python, but still get the error.

File “C:\Users\bernie\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\repls\subprocess\_repl.py”, line 209, in is\_alive  
return self.popen.poll() is None  
File “./python3.3/subprocess.py”, line 930, in poll  
File “./python3.3/subprocess.py”, line 1145, in \_internal\_poll  
OSError: [WinError 6] The handle is invalid  
command: drag\_select {“event”: {“button”: 1, “x”: 30.5, “y”: 792.5}}

---

<div class="post-metadata">

**Author:** ![nil](https://forum.sublimetext.com/letter_avatar_proxy/v4/letter/n/a183cd/32.png) [@nil](https://forum.sublimetext.com/u/nil)\
**Post date:** [February 17, 2025, 10:46am UTC](https://forum.sublimetext.com/t/how-to-map-a-key-to-sublimerepl-command/26569/6 "2025-02-17T10:46:04Z")

</div>

The issue can be sloved by modify the file subprocess\_repl.py

Go to line 209, you will find

```auto
def is_alive(self):
    return self.popen.poll() is None

```

change to

```auto
def is_alive(self):
    # return self.popen.poll() is None
    return True

```

[Here](https://github.com/wuub/SublimeREPL/issues/271) are the discussion.
