Question

In it is possible to run the current line instead of the whole file using ctrl (or cmd) + enter. This is handy when you want to test just a piece of code separated from the rest.

I have just started using Sublime Text 2 with Python. I have figured out how to build the file directly from Sublime Text 2 with cmd+b (I had first to adjust the python.sublime-build file so it could get the right path).

But it would be nice to run just the current line (directly from Sublime Text 2) instead of the whole file sometimes. Is it possible to do it? If not, is there another IDE where it is possible?

Was it helpful?

Solution

@Ermias already provided the URL to the plugin you need - SublimeREPL. It's best to install it via Package Control so you can stay current with updates and bug fixes. After you've installed it, you may need to customize the path to your Python interpreter - following my answer here will help you create the proper file to add more items to the Tools -> SublimeREPL -> Python menu. That answer is oriented towards Anaconda, but it can easily be used to add interpreters for both Python 2 and Python 3, for example, along with related IPython entries for each, or for adding multiple virtualenvs.

Once you have everything set up and tested, start a single REPL of your choice. SublimeREPL gets confused if more than one REPL is running of the same language type and you try to send a line, selection, or file to it. For example, if I have both Python 2 and 3 REPLs running along with an open file buffer containing a Python program I'm writing, selecting Tools -> SublimeREPL -> Eval in REPL -> Lines will lead to indeterminate results - I don't know which REPL it will send to, if any.

So there you have it. Check out the Eval in REPL and Transfer to REPL menus, and note the keyboard shortcuts. They're of the form Ctrl,, L, where you hit Ctrl, first, let up, then hit L.

Good luck!

OTHER TIPS

Check out SublimeREPL, which runs an interpreter inside sublime, available at https://github.com/wuub/SublimeREPL

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top