-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support IPython for Shift+Enter (execute line in terminal) #17172
Comments
Thanks for the feature request! We are going to give the community 60 days from when this issue was created to provide 5 👍 upvotes on the opening comment to gauge general interest in this idea. If there's enough upvotes then we will consider this feature request in our future planning. If there's unfortunately not enough upvotes then we will close this issue. |
Thank you! |
This issue is funny, because sometimes I get the desired behavior already, and sometimes I don't, depending on my conda environment. Environment A from CONDA-FORGE: So if I highlight the following and do shift+enter: x = 5
y = x**2
def squareIt(x):
return x**2 The IPython console looks like this: In [1]: x = 5
In [2]: y = x**2
In [3]: def squareIt(x):
...: return x**2
...:
In [4]: Environment B from DEFAULTS (Anaconda): So if I highlight the following and do shift+enter: x = 5
y = x**2
def squareIt(x):
return x**2 The IPython console looks like this: In [1]: x = 5
...: y = x**2
...: def squareIt(x):
...: return x**2
...:
...: I'm on Windows 10, and the latest install of VSCode, but no insiders channel, or similar. I don't know if the difference in behavior is from the |
Since it might not be clear, here is how I currently get SHIFT+ENTER to send code to IPython. I first run a dummy line of code and do SHIFT+ENTER. This opens a terminal, and runs (sometimes...) the code in the normal python REPL. Then I type I think you can achieve the same behavior of running in the IPython terminal by adding this to your
(Just for reference, it appears that this issue has been around for awhile, and inconsistently reproduced. Perhaps the conda channel choice is the key to understanding the different observations. #169; ipython/ipython#13054). You'll also see various 3rd party VSCode extensions that people have created to try to work around this issue. |
There have been various hacks proposed on the github issues and SO adding delays, and the like, to cause IPython to actually run the commands sent with SHIFT+ENTER. Perhaps the differences I observe based on package channel are somehow causing needed delays so occur automatically, by say using an unoptimized pyqt, event loop, or something, in the background to process the REPL on IPython side. |
Thank you to everyone who upvoted this issue! Since the community showed interest in this feature request we will leave this issue open as something to consider implementing at some point in the future. We do encourage people to continue 👍 this issue as it helps us prioritize our work based on what the community seems to want the most. |
Mysteriously, this now works on the same machine & env where it did not work when I opened #16744. Was there something changed in a recent VSCode release that might account for it working now? |
@sergeyf , check my comment here. I've had this work properly with and environment taken from conda-forge, and not work with one from Anaconda. So make sure it isn't just your environment, but where you're getting your builds from. |
Thanks @ryan-feeley. Pretty sure I haven't changed my environments since reporting originally. Just updated VSCode. |
I have this problem off and on as well. You can get around it if you have the multi-command extension by adding the following to your keybindings.json:
I stole the solution from here with some slight modifications. Mostly adding an interval as the commands were happening too quickly sometimes. |
Works well! |
From vs code version higher than 1.71 it seems not to work properly any more. When I am running more than one line, each line is executed separately. I found a solution to simulate 'ctrl+o' shortcut as a first step, which is adding line break in ipython terminal. The only problem is that any comment in code breaks this. Here is the code which needs to be added as first
|
Thanks for the solution! If you don't mind, having to configure an interval in between commands seems a bit forced to me. It works fine, but I was wondering if there are other solutions? As a note, I've tried installing different versions of python (3.7 - 3.11), with ipython installed from conda-forge and Anaconda but all of them have the same bug. I am on Windows 10. |
Now, almost in 2025, this issue still happens. In my case, running a selected text in terminal (not in REPL windows, not in IPython), the indentation has weird behavior in terminal output, it seems like each line gains additional blank spaces as lines goes down and I don't why, like this:
The "good news" is that my tests suggested me that it is a matter related with the Python version and not with Anaconda. The behavior above was seen when I run the selected text with Shift+Enter using the lasted Python at the moment, i.e. 3.13.0, which was automatically installed in my Conda env (not the base) as no Python version was specified. When I downgraded Python version to 3.12.7 (the last 3.12.x), every thing worked fine:
After getting struggle for some time trying a lot of solutions, that's my take, I hope this can help. |
Thank you all for showing interest for iPython support and continuing to show interest via upvoting the issue itself. In the meantime, I just wanted to inform everyone we have something called Native REPL now: https://code.visualstudio.com/docs/python/run#_native-repl which should provide useful features like intellisense, syntax highlighting (although it is an editor stye based REPL). I'm very curious to see what people think about this (goods and bads compared to ipython, cpython IDLE, other REPL experiences you have had with Python), so we have better sense of what the community really wants in regards to REPL in VS Code going forward. Best, |
I've commented in #22139 (comment). |
Discussed in #16744
Originally posted by sergeyf July 20, 2021
Environment data
python.languageServer
setting: pylance-2021.7.4Expected behaviour
Pressing Shift + Enter copies code to the terminal and executes it
Actual behaviour
Pressing Shift + Enter copies code to the terminal but it doesn't execute
Steps to reproduce:
EDIT: #18177 could resolve this.
The text was updated successfully, but these errors were encountered: