如何强制SHIFT + ENTER运行选择并立即在vscode中运行ipython来执行选择? [英] How can i force SHIFT+ENTER to run selection and execute it immediately running ipython in vscode?

查看:549
本文介绍了如何强制SHIFT + ENTER运行选择并立即在vscode中运行ipython来执行选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have added the setting below in vscode to launch ipython when i used shift+enter to run selection.

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

现在,当我运行选择时,代码将不会立即在终端中执行,我需要导航到终端并按Enter直到它执行. 如果我仅使用基本的python终端执行单行,则不会发生此问题.

Now when i run a selection, the code will not execute in the terminal immediately, i need to navigate to the terminal and hit enter until it does. This problem doesn't occur if i just use the basic python terminal to execute single lines.

是否有解决此问题的设置,因此该代码段可在终端中立即运行?我搜索了首选项,找不到任何东西.

Is there a setting to fix this so the snippet runs immediately in the terminal? I've searched preferences and can't find anything.

print("Hello World")

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

推荐答案

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

I was able to make some workaround.

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

And then you can use this command as shortcut (add to keybindings.json):

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

不幸的是,第一次(未打开ipython控制台时),您需要按Enter键.但是后来它可以正常工作了.

Unfortunately for the first time (when ipython console is not opened) you need to hit enter. But later it works as it should.

这篇关于如何强制SHIFT + ENTER运行选择并立即在vscode中运行ipython来执行选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆