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

如何在VSCode中设置特定快捷键?及Vim扩展下快速打开菜单与终端命令历史的Ctrl+J/K导航快捷键配置方法

Got it, let's walk through this step by step— I’ve dealt with that annoying Ctrl+K chord prompt while using VSCode + Vim before, so I know exactly how to get your desired shortcuts working.

Step 1: Open the Keyboard Shortcuts JSON File

VSCode’s graphical shortcut editor can be limiting for context-specific bindings, so we’ll use the raw JSON config for precision:

  • Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (Mac) to open the command palette.
  • Type and select Preferences: Open Keyboard Shortcuts (JSON). This will open your custom keybindings file.

Step 2: Add the Custom Keybindings

Paste the following configuration into the JSON file (replace or merge with existing entries if you have them):

[
  // Quick Open menu navigation
  {
    "key": "ctrl+k",
    "command": "workbench.action.quickOpenSelectPrevious",
    "when": "inQuickOpen"
  },
  {
    "key": "ctrl+j",
    "command": "workbench.action.quickOpenSelectNext",
    "when": "inQuickOpen"
  },

  // Terminal command history navigation
  {
    "key": "ctrl+k",
    "command": "workbench.action.terminal.historyPrevious",
    "when": "terminalFocus && terminalHistoryNavigationVisible"
  },
  {
    "key": "ctrl+j",
    "command": "workbench.action.terminal.historyNext",
    "when": "terminalFocus && terminalHistoryNavigationVisible"
  },

  // Disable the default Ctrl+K chord prompt in other contexts
  {
    "key": "ctrl+k",
    "command": "-workbench.action.showCommands",
    "when": "!inQuickOpen && !terminalHistoryNavigationVisible"
  }
]

What Each Part Does:

  • Quick Open Bindings: The inQuickOpen context ensures Ctrl+K/Ctrl+J only control selection when you’re in the Quick Open menu (opened via Ctrl+P or Ctrl+Shift+P).
  • Terminal History Bindings: The terminalHistoryNavigationVisible context triggers these shortcuts only when you’re browsing terminal command history (opened via Ctrl+R in the terminal).
  • Disable Chord Prompt: The - prefix in front of workbench.action.showCommands disables VSCode’s default behavior of treating Ctrl+K as a shortcut prefix in all contexts except Quick Open and terminal history. That’s what eliminates the "waiting for second key" message.

Vim Extension Compatibility Check

If you still run into conflicts with the Vim extension:

  • Open the command palette and select Preferences: Open Keyboard Shortcuts (the graphical editor).
  • Search for ctrl+k or ctrl+j to see if Vim has overlapping bindings.
  • If there are conflicts, you can add !vim.mode == 'normal' (or other Vim mode contexts) to the when clause of our custom bindings to ensure they take priority in the right scenarios.

Test It Out:

  1. Open Quick Open with Ctrl+P—use Ctrl+J/Ctrl+K to navigate options.
  2. Open the terminal, press Ctrl+R to pull up command history, then use Ctrl+J/Ctrl+K to cycle through entries.
  3. Press Ctrl+K outside of these contexts—you shouldn’t see the chord prompt anymore.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.28 23:47:45