要在集成终端中以交互方式运行代码,一次一行或多个选定行,只需按 ctrl+enter,我执行了以下操作:
安装macros 扩展。
将以下内容添加到User Settings
"macros": {
"canCopyEmpty": [
"expandLineSelection",
"editor.action.clipboardCopyAction",
"cancelSelection"
],
"runLine": [
"macros.canCopyEmpty",
"workbench.action.terminal.paste",
{
"command": "workbench.action.focusActiveEditorGroup",
"when": "terminalFocus"
}
],
"runSelection": [
"workbench.action.terminal.runSelectedText",
"cursorDown"
]
}
- 将以下内容添加到
keybindings.json
{
"key": "ctrl+enter",
"command": "macros.runLine",
"args": {
"cmd": "ls",
"match": ".*"
},
"when": "editorTextFocus && !editorHasSelection"
},
{
"key": "ctrl+enter",
"command": "macros.runSelection",
"args": {
"cmd": "ls",
"match": ".*"
},
"when": "editorTextFocus && editorHasSelection"
}