How can i force SHIFT+ENTER to run selection and execute it immediately running ipython in vscode?

雨燕双飞 提交于 2020-05-26 07:57:30

问题


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()\""
]

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")
   ...: 

回答1:


I was able to make some workaround.

You need to install extension multi-command.

Add this code in 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"
        ]
    },
]

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'" 
  }

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



来源:https://stackoverflow.com/questions/54332723/how-can-i-force-shiftenter-to-run-selection-and-execute-it-immediately-running

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!