15

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?

Community
  • 1
  • 1
Gabriel
  • 40,504
  • 73
  • 230
  • 404

3 Answers3

13

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. enter image description here

Daniel
  • 515
  • 4
  • 13
  • This is NOT working with Sublime Text 3 (3207). It will only build new tabs instead of re-using the same one. – John Stud Jul 20 '19 at 22:52
  • Works as expected for ST3 (3207) on linux mint 19. The only thing missing is a message to visually separate previous results from the new ones. Any idea where to incorporate that? @Daniel – Traxidus Wolf Aug 23 '19 at 07:35
  • 2
    to automatically change the focus to the the used repl view use `window.focus_view(found)` whitin the same if statement – Traxidus Wolf Aug 23 '19 at 07:41
  • @John Stud - verified working in ST3 build 3211, please update to resolve. – Daniel Mar 08 '20 at 00:34
  • @Traxidus Wolf - I've been reading but so far nothing. I thought perhaps a possible option within the "repl_view_settings" under the SublimeREPL user-defined settings or something like that, perhaps. – Daniel Mar 08 '20 at 00:57
  • Works fine for me on Sublime Text 3 (3211) and SublimeREPL v2.1.2, under macOS 11.01 (Big Sur) – Martin CR Nov 29 '20 at 19:32
  • this works for me on Windows with recent versions of ST3 and SublimeREPL except that this happens to break when I reorganize ST3 layout, e.g. pulling out the tab of the *REPL* – tagoma Jul 23 '21 at 13:38
3

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.

VivienG
  • 2,143
  • 3
  • 24
  • 43
3

I have found a better way to do this using Terminus

  1. install terminus
  2. create a new build system
  3. enter the following in the build system:
{
    "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"},
}
  1. now build using this new build system

screenshot of using terminus like repl:

enter image description here

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-

  1. create a new build system
  2. enter the following in the build system:
{
    "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"},
}
  1. now build using this new build system
  2. also be sure to add these into the key - binding
[
    //----------------------- 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"}]
    },
]
  1. the 1st one allows you to create a cmd shell in the default console area(ctrl + enter) and 2nd one allows to close the default console by closing terminus(ctrl + x) that's it enjoy.

screenshot of terminus in console:

enter image description here

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

Gabriel
  • 40,504
  • 73
  • 230
  • 404
Jishnu
  • 106
  • 9