gpt4 book ai didi

python - 我如何强制 SHIFT+ENTER 运行选择并立即在 vscode 中运行 ipython 执行它?

转载 作者:行者123 更新时间:2023-12-05 05:12:40 29 4
gpt4 key购买 nike

我在 vscode 中添加了以下设置,以便在我使用 shift+enter 运行选择时启动 ipython。

"python.terminal.launchArgs": [
"-c",
"\"from IPython import start_ipython; start_ipython()\""
]

现在当我运行一个选择时,代码不会立即在终端中执行,我需要导航到终端并按回车键直到它执行。如果我只是使用基本的 python 终端执行单行,则不会出现此问题。

是否有解决此问题的设置,以便代码段立即在终端中运行?我搜索了首选项,但找不到任何内容。

print("Hello World")

In [1]: print("Hello World")
...:

最佳答案

我能够做出一些解决方法。

您需要安装扩展程序multi-command

settings.json中添加这段代码

"multiCommand.commands": [
{
"command": "multiCommand.executeIPython",
"interval": 40,
"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 控制台未打开时)您需要按回车键。但稍后它会正常工作。

编辑:使用 interval 参数效果更好。感谢:DEVNULLDNE answer

关于python - 我如何强制 SHIFT+ENTER 运行选择并立即在 vscode 中运行 ipython 执行它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54332723/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com