在Python交互窗口VSCode中交换shift-enter和回车

Jor*_*oer 10 python configuration visual-studio-code

在 vscode 的交互窗口中,按 Shift-Enter 运行刚刚键入的代码,然后按 Enter 转到下一行。我可以换这个吗? 在此输入图像描述

小智 4

当前的答案解释了如何让“enter”执行命令,但他们没有给你另一半:让shift+enter插入一个新行。这是完整的解决方案(我从类似问题的各种答案中汇总了多个解决方案,以感谢其他提供帮助的人)。额外奖励:我来自 MATLAB,所以我还在 ipython 窗口中使用“F9”执行选择。

打开keybindings.json(ctrl+shift+p,打开键盘快捷键(JSON)添加以下内容:

    [
    {
        "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'"
    }
]
Run Code Online (Sandbox Code Playgroud)