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

VSCode中如何配置模式依赖的Vim风格快捷键o?

解决方案

VSCodeVim的自定义键映射不支持直接在commands数组中使用when条件,需要借助VSCode内置的workbench.action.runCommands命令来实现条件分支逻辑。

将以下配置添加到你的settings.json中:

"vim.normalModeKeyBindings": [
    {
        "before": ["o"],
        "commands": [
            {
                "command": "workbench.action.runCommands",
                "args": {
                    "commands": [
                        {
                            "command": "workbench.action.debug.stepOver",
                            "when": "inDebugMode && editorTextFocus && debugState == 'running'"
                        },
                        {
                            "command": "editor.action.insertLineAfter",
                            "when": "!inDebugMode || debugState != 'running'"
                        }
                    ]
                }
            }
        ]
    }
]

关键说明:

  • 使用vim.normalModeKeyBindings配置普通模式下的o键映射(o属于Vim普通模式命令)
  • 借助workbench.action.runCommands实现条件判断:
    • 当调试处于运行状态(inDebugMode && debugState == 'running')时,执行单步跳过操作
    • 非调试状态或调试未运行时,执行默认的插入新行操作
  • 修正了原配置中debugState == 'stopped'的逻辑问题——调试停止时stepOver无意义,改为检测调试运行状态

内容的提问来源于stack exchange,提问作者bradgonesurfing

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 19:47:30