Keybindings
Visual Studio Code offers a powerful and flexible way to customize your keybindings to match your workflow. You can rebind any command to your preferred key combination.
Default Keybindings
VS Code comes with a comprehensive set of default keybindings for various operating systems. These are designed to be ergonomic and efficient.
Common Keybindings (Windows/Linux)
| Command | Default Shortcut |
|---|---|
| Show All Commands | Ctrl+Shift+P |
| Open Settings | Ctrl+, |
| Toggle Terminal | Ctrl+` |
| Save File | Ctrl+S |
| Save All | Ctrl+K S |
| Copy Line Up | Alt+Up Arrow |
| Copy Line Down | Alt+Down Arrow |
| Delete Line | Shift+Delete |
| Find | Ctrl+F |
| Replace | Ctrl+H |
| Go to Definition | F12 |
| Peek Definition | Alt+F12 |
| Toggle Sidebar | Ctrl+B |
| Close Editor | Ctrl+W |
Common Keybindings (macOS)
| Command | Default Shortcut |
|---|---|
| Show All Commands | Cmd+Shift+P |
| Open Settings | Cmd+, |
| Toggle Terminal | Ctrl+` |
| Save File | Cmd+S |
| Save All | Cmd+K S |
| Copy Line Up | Option+Up Arrow |
| Copy Line Down | Option+Down Arrow |
| Delete Line | Cmd+Delete |
| Find | Cmd+F |
| Replace | Cmd+Option+F |
| Go to Definition | F12 |
| Peek Definition | Option+F12 |
| Toggle Sidebar | Cmd+B |
| Close Editor | Cmd+W |
Customizing Keybindings
You can easily customize keybindings through the Keyboard Shortcuts editor. To open it:
- Press Ctrl+K Ctrl+S (or Cmd+K Cmd+S on macOS).
- Alternatively, go to File > Preferences > Keyboard Shortcuts (or Code > Preferences > Keyboard Shortcuts on macOS).
The editor displays all available commands and their assigned keybindings. You can:
- Search: Use the search bar at the top to find specific commands or keybindings.
- Add/Change: Double-click on a command's keybinding to edit it. You can also right-click and select "Add Keybinding" or "Change Keybinding".
- Remove: Right-click on a keybinding and select "Remove Keybinding".
- Specify Context: For advanced customization, you can specify when a keybinding is active using the
whenclause.
The keybindings.json File
For more direct control and to manage complex configurations, VS Code uses a keybindings.json file. You can access this file by clicking the `{}` icon in the top right corner of the Keyboard Shortcuts editor.
Here's an example of how to add a custom keybinding:
{
"key": "ctrl+alt+c",
"command": "workbench.action.showCommands",
"when": "editorTextFocus"
}
This example assigns the "Show All Commands" action to Ctrl+Alt+C, but only when the editor has focus.
Keybinding Conflicts
If multiple keybindings are assigned to the same command, or if a keybinding is assigned to multiple commands, VS Code will highlight these conflicts in the Keyboard Shortcuts editor. You can resolve conflicts by removing or changing one of the conflicting keybindings.
Tip: You can import keymaps from other popular editors like Sublime Text, Atom, and Emacs via the Extensions Marketplace. Search for "keymap" to find them.
Common Keybinding Concepts
- Chorded Keybindings: A sequence of key presses, like Ctrl+K S. The first part (Ctrl+K) waits for the second part (S) to complete the command.
whenClauses: Conditions that determine when a keybinding is active. Examples include:editorTextFocus: When the text editor has focus.terminalFocus: When the integrated terminal has focus.explorerViewletVisible: When the File Explorer is visible.
Mastering VS Code's keybindings can significantly boost your productivity. Experiment with customizations to find what works best for you!