You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 20:07:03