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?

- 133
- 6
-
1did you figure this out? – Derek Eden Apr 27 '20 at 14:21
-
@DerekEden unfortunately no. – Jorrit de boer Apr 29 '20 at 12:26
-
lol, this is the only reason I don't use interactive window.....I tried changing the keyboard shortcut but it wouldnt let me use Enter – Derek Eden Apr 29 '20 at 13:02
3 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'"
}
]

- 86
- 5
I was able to do this finally by editing the "keybindings.json" file. If you click the "Open Keyboard Shortcuts (JSON)" button at the top right of the "Keyboard Shortcuts" window, it will open this file, and then you can edit/add it yourself. For example, it may look like this... the last item is the new one that does the trick for this specific shortcut:
// Place your key bindings in this file to override the defaultsauto[]
[
{
"key": "f9",
"command": "-editor.debug.action.toggleBreakpoint",
"when": "debuggersAvailable && editorTextFocus"
},
{
"key": "f9",
"command": "jupyter.execSelectionInteractive",
"when": "editorTextFocus && !jupyter.ownsSelection && !findInputFocussed && !notebookEditorFocused && !replaceInputFocussed && editorLangId == 'python'"
},
{
"key": "enter",
"command": "jupyter.execSelectionInteractive",
"when": "resourceScheme == 'vscode-interactive'"
},
]
It took me a bit of trial and error to make it so that "enter" caused the interactive cell to run, but did not also cause the editor to "run" every time I hit "enter" within it.

- 43
- 1
- 1
- 5
I better version that cleans the code block is :
// Place your key bindings in this file to override the defaults
[{
"key": "enter",
"command": "interactive.execute",
"when": "!suggestWidgetVisible && resourceScheme == 'vscode-interactive'"
},
]

- 11
- 2
-
2As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 24 '22 at 00:20
-
This is the best answer, it not only sends your code to the interactive window but also clears the console for your next command – Jeff Bezos Oct 14 '22 at 15:21
-