当我使用shift+enter运行选择时,我已经在vscode中添加了下面的设置来启动ipython。
"python.terminal.launchArgs": [
"-c",
"\"from IPython import start_ipython; start_ipython()\""
]现在,当我运行选择时,代码不会立即在终端中执行,我需要导航到终端并按enter,直到它执行为止。如果我只使用基本的python终端来执行单行代码,就不会出现这个问题。
有没有一个设置可以修复这个问题,这样代码片段就可以立即在终端中运行?我搜索了首选项,但什么也找不到。
print("Hello World")
In [1]: print("Hello World")
...: 发布于 2020-05-10 00:21:11
我可以做一些变通的方法。
您需要安装扩展multi-command。
在settings.json中添加此代码
"multiCommand.commands": [
{
"command": "multiCommand.executeIPython",
"sequence": [
"python.execSelectionInTerminal",
"workbench.action.terminal.focus",
"workbench.action.terminal.scrollToBottom",
{"command": "workbench.action.terminal.sendSequence",
"args": { "text": "\u000D" }},
"workbench.action.focusActiveEditorGroup"
]
},
]然后,您可以使用此命令作为快捷方式(添加到keybindings.json):
{
"key": "shift+enter",
"command": "multiCommand.executeIPython",
"when": "editorTextFocus && !findInputFocussed && !python.datascience.ownsSelection && !replaceInputFocussed && editorLangId == 'python'"
}不幸的是,第一次(当ipython控制台没有打开时),您需要按enter键。但后来它就像它应该的那样工作。
https://stackoverflow.com/questions/54332723
复制相似问题