我开了一个issue in GitHub、@AdamAL also opened,但似乎他们并没有这样做的意图。这是其他用户的解决方法。
编辑:
我之前回答过一个解决方法,它需要 2 个 VSCode 扩展而不使用智能命令 jupyter.selectCellContents。
@AdamAL 使用此命令共享了一个更好的解决方案,但需要注意的是光标会丢失位置和仅关注 Python 终端。
@Maxime Beau 指出将 @AdamAL 解决方案扩展到活动终端(例如,可能是 IPython)
现在我正在收集所有答案并发布通用解决方案。此解决方案在仅运行一个单元格时不会丢失光标位置。还有另一个命令运行单元并前进到下一个单元(如在 Jupyter 中),它对活动终端(可能是 IPython)是通用的。
1.安装macros 扩展:
这个扩展有一些multi-command没有的额外命令(比如delay命令)
2。在 settings.json 中
"macros.list": {
"runCellinTerminal": [
"jupyter.selectCellContents",
"workbench.action.terminal.runSelectedText",
"cursorUndo",
{"command": "$delay","args": {"delay": 100}},
{"command": "workbench.action.terminal.sendSequence","args": { "text": "\n" }},
],
"runCellinTerminaladvance": [
"jupyter.selectCellContents",
"workbench.action.terminal.runSelectedText",
"cursorDown",
{"command": "$delay","args": {"delay": 100}},
{"command": "workbench.action.terminal.sendSequence","args": { "text": "\n" }},
],
}
OBS:cursorUndo 将光标带回正确的位置。 cursorDown 将光标移动到下一个单元格。当终端是 IPython 终端时,delay 和 sendSequence \n 命令很有用。
3.在 keybinding.json 中:
{
"key": "ctrl+alt+enter",
"command": "macros.runCellinTerminal",
"when": "editorTextFocus && jupyter.hascodecells"
},
{
"key": "shift+alt+enter",
"command": "macros.runCellinTerminaladvance",
"when": "editorTextFocus && jupyter.hascodecells"
},