7

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?

Carlos Cinelli
  • 11,354
  • 9
  • 43
  • 66

2 Answers2

5

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

Community
  • 1
  • 1
MattDMo
  • 100,794
  • 21
  • 241
  • 231
1

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

Ermias
  • 33
  • 6
  • 1
    umm, don't you mean "Check out SublimeREPL, which runs..."? – MattDMo Mar 09 '14 at 17:25
  • @mattDMo you could write a more complete answer, this answer helped me (because I did not know that sublimeREPL could do that) but it is a very poor answer. I also had to configure the correct path to Python using your other answer: http://stackoverflow.com/questions/20861176/how-do-i-setup-sublimerepl-with-anacondas-interpreter – Carlos Cinelli Mar 09 '14 at 19:04
  • @carloscinelli - what other detail do you need? If my linked answer helped you, you can always vote for it there - we don't want to be replicating answers on StackOverflow if at all possible. – MattDMo Mar 09 '14 at 19:08
  • I already upvoted you there! I just thougth that if someone could either edit Ermias answer or put a better one it would make easier to the next person who searches for this. I tried to edit his answer but I think the moderators did not approve. But it not essential, I have solved it already! – Carlos Cinelli Mar 09 '14 at 19:14
  • 1
    @carloscinelli OK, I'll make a more complete answer to this question. – MattDMo Mar 09 '14 at 19:15