问题
In VS Code with Python, we can run a "cell" (block that starts with #%%
) in the "Python Interactive Window"
Can we do the same thing on the Integrated Terminal?
I know we can do this in Spyder, where the terminal is generally always an IPython terminal
Matlab works in the same way with its terminal.
Can we do this in VS Code?
回答1:
I've opened a issue in GitHub, but it seems they don't have intention to do this.
I'm putting a workaround, for other users:
1. Have "Select By" extension:
https://marketplace.visualstudio.com/items?itemName=rioj7.select-by
https://github.com/rioj7/select-by
2. Have "macro" extension:
https://marketplace.visualstudio.com/items?itemName=ctf0.macros
https://github.com/ctf0/macros
3. Put the bellow in settings.json
:
"selectby.regexes": {
"regex1": {
"flags": "i",
"backward": "#.*%%.*\r",
"forward": "#.*%%.*\r",
"backwardInclude": false,
"forwardInclude": false
},
},
"macros.list": {
"RunCellinTerminal": [
"cursorEnd",
"selectby.regex1",
"workbench.action.terminal.runSelectedText",
"cursorEnd",
]
}
4. Execute the macro "RunCellinTerminal"
With the cursor inside a desired cell, when the macro is executed, the cell's region will be selected and the text will be send to the opened active terminal.
Here's a example: (it is possible to add a key-bind)
来源:https://stackoverflow.com/questions/61275551/python-in-vs-code-can-i-run-cell-in-the-integrated-terminal