Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run the current line (not the whole file) in Sublime Text 2?

In rstudio 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?

like image 345
Carlos Cinelli Avatar asked Mar 09 '14 15:03

Carlos Cinelli


2 Answers

@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!

like image 199
MattDMo Avatar answered Sep 18 '22 16:09

MattDMo


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

like image 29
Ermias Avatar answered Sep 18 '22 16:09

Ermias