In this question How to Run Python Code on SublimeREPL, an answer is given on how to use the usual Ctrl+b
shortcut to run a python code using SublimeREPL within SublimeText.
The steps are simple:
1- Create a new empty file and paste into it the commands:
{
"target": "run_existing_window_command",
"id": "repl_python_run",
"file": "config/Python/Main.sublime-menu"
}
2- Save the file as:
/home/USER/.config/sublime-text-3/Packages/User/SublimeREPL-python.sublime-build
3- Go to your Python file tab and select:
Tools > Build System > SublimeREPL-python
After that the usual Ctrl+b
shortcut will open a new tab where the code is executed.
The issue with this is that the tabs are not re-used. This means every time you hit Ctrl+b
, a new tab opens up instead of the code running in the same tab that was opened before.
Is there a way to make SublimeREPL re-use the tab?
Add the following line in the "repl_python_run" command in SublimeREPL\config\Python\Main.sublime-menu, right before the "external_id": "python" argument:
"view_id": "*REPL* [python]",
and then to change the line:
if view.id() == view_id
into:
if view.name() == view_id
in SublimeREPL\sublimerepl.py.
Found here.
Unfortunatly you can't do that even on the latest version of SublimREPL. What you can do is open a ticket to the developper to ask for this implementation. But I'm not sure Sublime Text is able to do that.
I have found a better way to do this using Terminus
{ "target": "terminus_open", "title": "Python REPL", "tag": "python-repl", "auto_close": false, "shell_cmd": "python -u -i \"$file\"", "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python", "env": {"PYTHONIOENCODING": "utf-8"}, }
screenshot of using terminus like repl:
This will basically create a repl for you without the new tab opening after each build, you can further modify it with origami to show the console on right, left, up, bottom of your screen if you want too.
You can also use terminus and run it in the default output console window while accepting inputs and making it interactable too for this-
{ "target": "terminus_exec", "cancel": "terminus_cancel_build", "focus": true, "timeit": false, "shell_cmd": "python -u -i \"$file\"", "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python", "env": {"PYTHONIOENCODING": "utf-8"}, }
[ //----------------------- OPEN CMD CONSOLE ----------------------- { "keys": ["ctrl+enter"], // you can change the keys "command": "terminus_open", "args" : { "cmd": "cmd.exe", "cwd": "${file_path:${folder}}", "panel_name": "Terminus" } }, //----------------------- CLOSE TERMINUS CONSOLE ----------------------- { "keys": ["ctrl+x"], "command": "terminus_close", // you can change the keys "context": [{ "key": "terminus_view"}] }, ]
screenshot of terminus in console:
I wasted a lot of time trying to find a way to re use tab in repl that's when i found out sublime repl isn't actively maintained anymore. thats how i found terminus which is actively maintained and can do similar things like repl, hope this helps you.
here is the github guide link: https://github.com/wuub/SublimeREPL/issues/481#issuecomment-917862655
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With