如何在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) orCmd+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
inQuickOpencontext ensuresCtrl+K/Ctrl+Jonly control selection when you’re in the Quick Open menu (opened viaCtrl+PorCtrl+Shift+P). - Terminal History Bindings: The
terminalHistoryNavigationVisiblecontext triggers these shortcuts only when you’re browsing terminal command history (opened viaCtrl+Rin the terminal). - Disable Chord Prompt: The
-prefix in front ofworkbench.action.showCommandsdisables VSCode’s default behavior of treatingCtrl+Kas 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+korctrl+jto see if Vim has overlapping bindings. - If there are conflicts, you can add
!vim.mode == 'normal'(or other Vim mode contexts) to thewhenclause of our custom bindings to ensure they take priority in the right scenarios.
Test It Out:
- Open Quick Open with
Ctrl+P—useCtrl+J/Ctrl+Kto navigate options. - Open the terminal, press
Ctrl+Rto pull up command history, then useCtrl+J/Ctrl+Kto cycle through entries. - Press
Ctrl+Koutside of these contexts—you shouldn’t see the chord prompt anymore.
内容的提问来源于stack exchange,提问作者theDude823
相关产品推荐
相关产品推荐

