如何强制换档+;输入以运行选择并立即在vscode中运行ipython执行它?

如何强制换档+;输入以运行选择并立即在vscode中运行ipython执行它?,python,visual-studio-code,ipython,Python,Visual Studio Code,Ipython,我在vscode中添加了以下设置,以便在使用shift+enter运行选择时启动ipython "python.terminal.launchArgs": [ "-c", "\"from IPython import start_ipython; start_ipython()\"" ] 现在,当我运行选择时,代码不会立即在终端中执行,我需要导航到终端并按enter键,直到它执行为止。 如果我只使用基本python终端执行单行代码,就不会出现这个问题 是否有设置来修复此问题,以

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

"python.terminal.launchArgs": [
    "-c",
    "\"from IPython import start_ipython; start_ipython()\""
]
现在,当我运行选择时,代码不会立即在终端中执行,我需要导航到终端并按enter键,直到它执行为止。 如果我只使用基本python终端执行单行代码,就不会出现这个问题

是否有设置来修复此问题,以便代码段立即在终端中运行?我搜索了偏好,但什么也找不到

print("Hello World")

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

我能做些变通

您需要安装扩展名
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
):

不幸的是,第一次(当ipython控制台未打开时)您需要按enter键。但后来,它的工作,因为它应该

  {
    "key": "shift+enter",
    "command": "multiCommand.executeIPython",
    "when": "editorTextFocus && !findInputFocussed && !python.datascience.ownsSelection && !replaceInputFocussed && editorLangId == 'python'" 
  }