Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swap shift-enter and enter in python interactive window VSCode

In the interactive window in vscode you press shift-enter to run the code you just typed and enter to go to the next line. Can I swap this? enter image description here

like image 807
Jorrit de boer Avatar asked Apr 09 '26 14:04

Jorrit de boer


1 Answers

The current answers explain how to make "enter" execute the command but they don't give you the other half: make shift+enter insert a new line. Here is the complete solution (I aggregated multiple solutions from various answers to similar questions to credit to everyone else who helped). Bonus: I come from MATLAB so I also made "F9" execute selection in the ipython window.

Open keybindings.json (ctrl+shift+p, open keyboard shortcuts (JSON) Add the following:

    [
    {
        "key": "enter",
        "command": "interactive.execute",
        "when": "!suggestWidgetVisible && resourceScheme == 'vscode-interactive'"
    },
    {
        "key": "shift+enter",
        "command": "",
        "when": "!suggestWidgetVisible && resourceScheme == 'vscode-interactive'"
    },
    {
        "key": "f9",
        "command": "jupyter.execSelectionInteractive",
        "when": "editorTextFocus && !findInputFocussed && !replaceInputFocussed && editorLangId == 'python'"
    }
]
like image 162
jvtnv Avatar answered Apr 11 '26 03:04

jvtnv