PTVS icon indicating copy to clipboard operation
PTVS copied to clipboard

Python Editor - SendSelectionToInteractive not working on VS2022

Open vsfeedback opened this issue 2 years ago • 4 comments

This issue has been moved from a ticket on Developer Community.


[severity:It's more difficult to complete my work] Hello,

When I code in Python in Visual Studio, I want to press "ctrl+enter" to execute the selection or the line I am in (without having to execute all the code above).

Without installing anything in particular in VS2019, except for the "Python Development" in Visual Studio Installer, it works fine. But in Visual Studio 2022 it is not working anymore, It does the "LineOpenAbove" command instead.

So It does the command as if it was a Text Editor and not a Python Editor : ! [image.png] (https://aka.ms/dc/image?name=B0bdde7b1393a42dc9839e60ff600e39a637823425661277144_20220308-142245-image.png&tid=0bdde7b1393a42dc9839e60ff600e39a637823425661277144)

With best regards, Theo Wendling


Original Comments

(no comments)


Original Solutions

(no solutions)

vsfeedback avatar Mar 08 '22 17:03 vsfeedback

It might have to do with ContentType not being detected correctly for .py files. Similar to the cause of #6784

StellaHuang95 avatar Jun 09 '22 21:06 StellaHuang95

I still have this problem on VS 2022 v17.3.5.

Have you found anything else, or did someone find a way to work around it ?

Denok67 avatar Oct 11 '22 09:10 Denok67

Still not working today on VS2022 v17.7.3.

For information, when I delete the "LineOpenAbove" shortcut in the keyboard options and try to do Ctrl+Enter on a Python code line, it opens the interactive window but does nothing. And when I try to type manually in this interactive window, it crashes : "The interactive Python process has exited."

For those having this issue, VS 2019 works fine with Python without having to mess around with the parameters.

If anyone manages to make it work, I'll be glad to know how. I really want to have only the VS 2022 installation for all my projects.

Denok67 avatar Sep 01 '23 09:09 Denok67

I've managed to make it work for us, not exactly sure what was the real issue, but here's what I've done so far :

  • First, I've uninstalled every Python environment except the one I needed.

  • Then in Keyboard options (Tools > Options... > Environment > Keyboard) :

  1. for command Edit.SendSelectionToInteractive : Remove everything and only assign Ctrl+Enter in Global
  2. for command Edit.LineOpenAbove : Remove the Ctrl+Enter bind
  3. then, on Ctrl+Enter bind, I have :
    • Edit.SendSelectionToInteractive (Ctrl+Enter (Global))
    • InteractiveConsole.ExecuteOrPasteInput (Ctrl+Enter (Interactive Window))
    • Team.Git.Commit (Ctrl+Enter (Git))

Now It works perfectly, it executes the line where the cursor is and places the cursor on the beginning of the next line.

I think I had 2 problems, Python environment was crashing because of my installations (maybe the wrong on was called by the interactive window ?). And the Edit.SendSelectionToInteractive works fine when bind with Global and does nothing when bind with Python Editor.

Now I can fully enjoy VS2022, Thanks for your work on PTVS 💯

Denok67 avatar Nov 21 '23 09:11 Denok67