Overview
The keybinding system consists of:- KeybindingsRegistry: Stores all default and extension-provided keybindings
- IKeybindingService: Runtime service that resolves keybindings and dispatches keyboard events
- ResolvedKeybinding: Platform-specific representation of keybindings
KeybindingsRegistry
The registry stores all built-in and extension-provided keybindings (but not user-defined ones):Registering Keybindings
Basic Keybinding Rule
Keybinding Rule Interface
Keybinding Weights
Weights determine priority when multiple keybindings conflict:Key Codes and Modifiers
Key Modifiers
Key Codes
Combining Keys
Combine modifiers and keys using the bitwise OR operator:Platform-Specific Keybindings
Define different keybindings per platform:Chord Keybindings
Chord keybindings are two-key sequences (like Ctrl+K Ctrl+C):Context-Aware Keybindings
Usewhen clauses to activate keybindings only in specific contexts:
Common Context Keys
Common Context Keys
Context Expression Examples
Context Expression Examples
IKeybindingService
The keybinding service resolves and dispatches keybindings at runtime:Using the Keybinding Service
Looking Up Keybindings
Appending Keybindings to Labels
Dispatching Keyboard Events
Registering with Action2
The recommended way to register keybindings is throughAction2:
Real-World Examples
Save File Keybinding
Save File Keybinding
Quick Open with Chord
Quick Open with Chord
Context-Specific Keybinding
Context-Specific Keybinding
Best Practices
Use KeyMod.CtrlCmd: Always use
KeyMod.CtrlCmd instead of KeyMod.WinCtrl for better cross-platform behavior. It automatically maps to Cmd on Mac and Ctrl elsewhere.Avoid conflicts: Check existing keybindings before registering new ones. Use appropriate weights and context expressions to avoid conflicts.
Provide alternatives: Consider providing secondary keybindings for discoverability and user preference.
Context awareness: Always use
when clauses to scope keybindings to appropriate contexts. This prevents unintended activation.Document chord sequences: Chord keybindings are powerful but less discoverable. Document them clearly in your extension’s README.