python执行命令shift,如何强制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()\""

]

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.

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值