VS Code如何将当前编辑器行发送至活动终端并下移光标?
把当前行发送到活动终端并自动下移光标
方法一:组合命令快捷键
打开VS Code的快捷键JSON配置文件(按Ctrl+K Ctrl+S后点击右上角的JSON图标),添加以下配置:
{ "key": "ctrl+enter", // 可替换为你偏好的快捷键组合 "command": "runCommands", "args": { "commands": [ "workbench.action.terminal.runSelectedText", "cursorDown" ] }, "when": "editorTextFocus && !editorHasSelection" }
- 作用:当编辑器有焦点且无选中内容时,按下设置的快捷键,会把光标所在行发送到活动终端,随后光标自动下移一行。
- 提示:如果不想用
ctrl+enter,可以换成其他不冲突的组合键,比如alt+enter。
方法二:分步骤绑定(更灵活)
同样在keybindings.json中添加:
{ "key": "enter", "command": "workbench.action.terminal.runSelectedText", "when": "editorTextFocus && !editorHasSelection && terminalFocus != true", "args": { "keepFocus": false } }, { "key": "enter", "command": "cursorDown", "when": "editorTextFocus && !editorHasSelection && terminalFocus != true && lastAction == 'workbench.action.terminal.runSelectedText'" }
- 作用:用Enter键触发发送当前行到活动终端,发送完成后自动下移光标。注意这种配置会覆盖默认Enter键换行功能,适合习惯用特定快捷键的用户。
内容的提问来源于stack exchange,提问作者user2649059
相关产品推荐
相关产品推荐

