skip to Main Content

I’m using VSCode extensively in my workflow together with the Vim extension.
I frequently execute single lines in the editor in Python interactive mode.
On Shift+Enter (with no characters highlighted) it is supposed to only execute the current line and not change the cursor position.

This behaviour changes sometimes and VSCode skips to the next non empty line in the editor after hitting Shift+Enter which hinders my desired workflow considerably.

This behaviour started showing up before, and a full reinstall fixed it. But now I did a full reinstall and Code still jumps the cursor to the next line on Shift+Enter.

Is there a way to prevent this and get the old behaviour persistently again?

My Keybindings and settings file look like this:

// Place your key bindings in this file to override the defaultsauto[]
[
    {
        "key": "shift+down",
        "command": "workbench.action.terminal.toggleTerminal",
        "when": "terminal.active"
    },
    {
        "key": "shift+up",
        "command": "workbench.action.focusActiveEditorGroup"
    }
]
{
    "workbench.colorTheme": "Default Dark Modern",
    "git.openRepositoryInParentFolders": "never",
}

I tried completly reinstalling (uninstall vscode, remove all local folders in appdata). This fixed the problem before. On encountering the problem again, I was not able to revert to the desired cursor behaviour with this approach.

The only keyboard shortcut active in editor with shift+enter is Python Run Selection/Line in Python terminal. To use this command the Python extension has to be activated, all others are deactivated.

Current keyboard shortucuts with shift+Enter

EDIT:

I found the solution with the help of the comments below:

The python extension version I was using was:
2023.20.0 which released about a two weeks ago.

Downgrading to 2023.18.0 fixed the problem. Apparently they added this feature per default but it would be nice to know how to deactivate without having to downgrade.

2

Answers


    1. Open the Keyboard Shortcuts page and click the Record Keys button on the right

      enter image description here

    2. Press the Shift and Enter keys

    3. Find results that do not meet expectations and delete them

      enter image description here

    Login or Signup to reply.
  1. Yep. This is a new change in version 2023.20.0 of the Python extension.

    In the release blogpost at https://devblogs.microsoft.com/python/python-in-visual-studio-code-november-2023-release/#improvements-to-shift-enter-run-line-in-terminal, they wrote:

    With our new experimental Smart Send feature, the Python extension will send the smallest runnable block of code surrounding the line where your cursor is to the REPL for execution. This ensures that only complete and executable sections of code are sent to the REPL. The cursor will also be automatically placed to the next executable line, to provide a smooth experience when executing multiple chunks iteratively.

    It’s also mentioned in the VS Code 1.84 release notes

    You can disable Smart Send by setting the python.REPL.enableREPLSmartSend VS Code setting contributed by the Python extension to false.

    The relevant issue ticket that tracked the addition of this feature is Dynamic Smart Cursor Movement #21838.

    Fun historical fact: This feature was requested before and declined. Interesting that now that make it the default behaviour.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search