I have looked at all the answers on this forum but I'm missing something. I want to be able to hit Cmd+B while editing a Python file "myfile.py" in Sublime Text 2.
This should open up a Python shell that loads my file and returns me to the interactive prompt so the namespace in my Python script is available.
Setting the -i
option in the build setting still closes the interpreter (see below)
> 81
> >>> [Finished in 0.1s]
I downloaded sublimeREPL but I'm not sure how to set the -i
option.
Any help is appreciated
ok, thanks to sneawo for the hints! Here's my first cut at doing this.
Step 1. Create a plugin pydev, (from Tools->New Plugin) which creates a command 'pydev'
Step 2. Create a new key binding in the Preferences->Key-Bindings-user
Now pressing f5 (on the Mac it will be fn+f5 by default) does the trick-it will start the python interpreter in a repl tab, set the layout to two-window horizontal and move the repl tab to the lower window.
This is pretty basic in that it doesn't check to see what the current layout is and simply sets the layout to 2-horizontal. Will probably spruce up the code to do some checking and simply add a horizontal window to the existing layout. Also would be good to remove the horizontal buffer when the repl tab is closed.
Try to update your user keybindings:
I wanted to add a quick edit to the answer by @user1936097.
I copied the idea but wanted to instead load IPython (the code as is works fine to load standard Python). I replaced...
with...
But it didn't work.
The line
"autocomplete_server": true
seemed to be the problem. If I removed it, the code ran, but IPython opened the closed. If I left it, nothing happened.I finally borrowed a command found in the file
/SublimeREPL/config/Python/Default.sublime-commands
and came up with...This made the final plugin code:
Assign this to a keybind as shown in the original post and you will now load IPython instead of standard Python!
Here is an easy way just creating a new build system.
Then save the build system as Python3 or Python27 and select it as default.
The answer is much more simple than your approach. Just define a new build "profile" (Build system), in it you capture exactly the default Python build, except changing option
-u
to-ui