Visual Studio Code Key Bindings
Visual Studio Code Key Bindings
Version 1.78 (/updates) is now available! Read about the new features and fixes from April. ×
✏ (https://vscode.dev/github/microsoft/vscode-docs/blob/main/docs/getstarted/keybindings.md)
Key Bindings for Visual Studio Code
Visual Studio Code lets you perform most tasks directly from the keyboard. This page lists out the default bindings (keyboard shortcuts) and describes how you can
update them.
Note: If you visit this page on a Mac, you will see the key bindings for the Mac. If you visit using Windows or Linux, you will see the keys for that platform. If you need
the key bindings for another platform, hover your mouse over the key you are interested in.
Most importantly, you can see keybindings according to your keyboard layout. For example, key binding Cmd+\ in US keyboard layout will be shown as
Ctrl+Shift+Alt+Cmd+7 when layout is changed to German. The dialog to enter key binding will assign the correct and desired key binding as per your keyboard layout.
For doing more advanced keyboard shortcut customization, read Advanced Customization (/docs/getstarted/keybindings#_advanced-customization).
Keymap extensions
Keyboard shortcuts are vital to productivity and changing keyboarding habits can be tough. To help with this, File > Preferences > Migrate Keyboard Shortcuts from...
shows you a list of popular keymap extensions. These extensions modify the VS Code shortcuts to match those of other editors so you don't need to learn new keyboard
shortcuts. There is also a Keymaps category (https://marketplace.visualstudio.com/search?target=VSCode&category=Keymaps&sortBy=Installs) of extensions in the
Marketplace.
https://code.visualstudio.com/docs/getstarted/keybindings#_detecting-keybinding-conflicts 1/15
22/5/23, 8:01 Visual Studio Code Key Bindings
Vim Sublime Text Keymap and Settings Imp… Atom Keymap Brackets Keymap
vscodevim 5.0M ms-vscode 1.9M ms-vscode 966.7K ms-vscode 140.1K
Tip: Click on an extension tile above to read the description and reviews to decide which extension is best for you. See more in the Marketplace
(https://marketplace.visualstudio.com/vscode).
Below are links to the three platform-specific versions (US English keyboard):
Windows (https://go.microsoft.com/fwlink/?linkid=832145)
macOS (https://go.microsoft.com/fwlink/?linkid=832143)
Linux (https://go.microsoft.com/fwlink/?linkid=832144)
The Keyboard Shortcuts editor has a context menu command Show Same Keybindings, which will filter the keybindings based on a keyboard shortcut to display
conflicts.
Pick a command with the keybinding you think is overloaded and you can see if multiple commands are defined, the source of the keybindings and when they are active.
https://code.visualstudio.com/docs/getstarted/keybindings#_detecting-keybinding-conflicts 2/15
22/5/23, 8:01 Visual Studio Code Key Bindings
Troubleshooting keybindings
To troubleshoot keybindings problems, you can execute the command Developer: Toggle Keyboard Shortcuts Troubleshooting. This will activate logging of dispatched
keyboard shortcuts and will open an output panel with the corresponding log file.
You can then press your desired keybinding and check what keyboard shortcut VS Code detects and what command is invoked.
For example, when pressing cmd+/ in a code editor on macOS, the logging output would be:
[KeybindingService]: / Received keydown event - modifiers: [meta], code: MetaLeft, keyCode: 91, key: Meta
[KeybindingService]: | Converted keydown event - modifiers: [meta], code: MetaLeft, keyCode: 57 ('Meta')
[KeybindingService]: \ Keyboard event cannot be dispatched.
[KeybindingService]: / Received keydown event - modifiers: [meta], code: Slash, keyCode: 191, key: /
[KeybindingService]: | Converted keydown event - modifiers: [meta], code: Slash, keyCode: 85 ('/')
[KeybindingService]: | Resolving meta+[Slash]
[KeybindingService]: \ From 2 keybinding entries, matched editor.action.commentLine, when: editorTextFocus && !editorReadonly, source: built-i
n.
The first keydown event is for the MetaLeft key ( cmd ) and cannot be dispatched. The second keydown event is for the Slash key ( / ) and is dispatched as meta+
[Slash] . There were two keybinding entries mapped from meta+[Slash] and the one that matched was for the command editor.action.commentLine , which has the
when condition editorTextFocus && !editorReadonly and is a built-in keybinding entry.
Advanced customization
All keyboard shortcuts in VS Code can be customized via the keybindings.json file.
To configure keyboard shortcuts through the JSON file, open Keyboard Shortcuts editor and select the Open Keyboard Shortcuts (JSON) button on the right of
the editor title bar.
This will open your keybindings.json file where you can overwrite the Default Keyboard Shortcuts (/docs/getstarted/keybindings#_default-keyboard-shortcuts).
You can also open the keybindings.json file from the Command Palette ( Ctrl+Shift+P ) with the Preferences: Open Keyboard Shortcuts (JSON) command.
Keyboard rules
Each rule consists of:
Chords (two separate keypress actions) are described by separating the two keypresses with a space. For example, Ctrl+K Ctrl+C .
https://code.visualstudio.com/docs/getstarted/keybindings#_detecting-keybinding-conflicts 3/15
22/5/23, 8:01 Visual Studio Code Key Bindings
if a rule is found and has a command set, the command is executed.
The additional keybindings.json rules are appended at runtime to the bottom of the default rules, thus allowing them to overwrite the default rules. The
keybindings.json file is watched by VS Code so editing it while VS Code is running will update the rules at runtime.
The keyboard shortcuts dispatching is done by analyzing a list of rules that are expressed in JSON. Here are some examples:
// Global keybindings
{ "key": "ctrl+f", "command": "actions.find" },
{ "key": "alt+left", "command": "workbench.action.navigateBack" },
{ "key": "alt+right", "command": "workbench.action.navigateForward" },
Accepted keys
The key is made up of modifiers and the key itself.
Platform Modifiers
Command arguments
You can invoke a command with arguments. This is useful if you often perform the same operation on a specific file or folder. You can add a custom keyboard shortcut to
do exactly what you want.
The following is an example overriding the Enter key to print some text:
{
"key": "enter",
"command": "type",
"args": { "text": "Hello World" },
"when": "editorTextFocus"
}
The type command will receive {"text": "Hello World"} as its first argument and add "Hello World" to the file instead of producing the default command.
For more information on commands that take arguments, refer to Built-in Commands (/api/references/commands).
1. Run several commands without arguments: copy current line down, mark the current line as comment, move cursor to copied line
https://code.visualstudio.com/docs/getstarted/keybindings#_detecting-keybinding-conflicts 4/15
22/5/23, 8:01 Visual Studio Code Key Bindings
{
"key": "ctrl+alt+c",
"command": "runCommands",
"args": {
"commands": [
"editor.action.copyLinesDownAction",
"cursorUp",
"editor.action.addCommentLine",
"cursorDown"
]
}
},
2. It is also possible to pass arguments to commands: create a new untitled TypeScript file and insert a custom snippet
{
"key": "ctrl+n",
"command": "runCommands",
"args": {
"commands": [
{
"command": "workbench.action.files.newUntitledFile",
"args": {
"languageId": "typescript"
}
},
{
"command": "editor.action.insertSnippet",
"args": {
"langId": "typescript",
"snippet": "class ${1:ClassName} {\n\tconstructor() {\n\t\t$0\n\t}\n}"
}
}
]
}
},
Note that commands run by runCommands receive the value of "args" as the first argument. So in the example above, workbench.action.files.newUntitledFile
receives {"languageId": "typescript" } as its first and only argument.
{
"key": "ctrl+shift+e",
"command": "runCommands",
"args": {
"commands": [
{
// command invoked with 2 arguments: vscode.executeCommand("myCommand", "arg1", "arg2")
"command": "myCommand",
"args": ["arg1", "arg2"]
}
]
}
}
To pass an array as the first argument, one needs to wrap the array in another array: "args": [ [1, 2, 3] ] .
Here is an example:
To override a specific key binding rule with an empty action, you can specify an empty command:
https://code.visualstudio.com/docs/getstarted/keybindings#_detecting-keybinding-conflicts 5/15
22/5/23, 8:01 Visual Studio Code Key Bindings
// To override and disable any `tab` keybinding, for example, add in keybindings.json:
{ "key": "tab", "command": "" }
Keyboard layouts
Note: This section relates only to key bindings, not to typing in the editor.
The keys above are string representations for virtual keys and do not necessarily relate to the produced character when they are pressed. More precisely:
Different keyboard layouts usually reposition the above virtual keys or change the characters produced when they are pressed. When using a different keyboard layout
than the standard US, Visual Studio Code does the following:
All the key bindings are rendered in the UI using the current system's keyboard layout. For example, Split Editor when using a French (France) keyboard layout is now
rendered as Ctrl+* :
When editing keybindings.json , VS Code highlights misleading key bindings, those that are represented in the file with the character produced under the standard US
keyboard layout, but that need pressing keys with different labels under the current system's keyboard layout. For example, here is how the Default Keyboard Shortcuts
rules look like when using a French (France) keyboard layout:
https://code.visualstudio.com/docs/getstarted/keybindings#_detecting-keybinding-conflicts 6/15
22/5/23, 8:01 Visual Studio Code Key Bindings
There is also a widget that helps input the key binding rule when editing keybindings.json . To launch the Define Keybinding widget, press Ctrl+K Ctrl+K . The widget
listens for key presses and renders the serialized JSON representation in the text box and below it, the keys that VS Code has detected under your current keyboard
layout. Once you've typed the key combination you want, you can press Enter and a rule snippet will be inserted.
Note: On Linux, Visual Studio Code detects your current keyboard layout on start-up and then caches this information. For a good experience, we recommend
restarting VS Code if you change your keyboard layout.
VS Code sets various context keys and specific values depending on what elements are visible and active in the VS Code UI. For example, the built-in Start Debugging
command has the keyboard shortcut F5 , which is only enabled when there is an appropriate debugger available (context debuggersAvailable is true) and the editor
isn't in debug mode (context inDebugMode is false):
https://code.visualstudio.com/docs/getstarted/keybindings#_detecting-keybinding-conflicts 7/15
22/5/23, 8:01 Visual Studio Code Key Bindings
You can also view a keybinding's when clause directly in the Default Keybindings JSON (Preferences: Open Default Keyboard Shortcuts (JSON)):
Conditional operators
For when clause conditional expressions, the following conditional operators are useful for keybindings:
Or || "isLinux || isWindows"
You can find the full list of when clause conditional operators in the when clause contexts (/api/references/when-clause-contexts#_conditional-operators) reference.
Available contexts
You can find some of the available when clause contexts in the when clause context reference (/api/references/when-clause-contexts).
The list there isn't exhaustive and you can find other when clause contexts by searching and filtering in the Keyboard Shortcuts editor (Preferences: Open Keyboard
Shortcuts ) or reviewing the Default Keybindings JSON file (Preferences: Open Default Keyboard Shortcuts (JSON)).
{
"key": "ctrl+shift+r ctrl+e",
"command": "editor.action.codeAction",
"args": {
"kind": "refactor.extract.function"
}
}
This is covered in depth in the Refactoring (/docs/editor/refactoring#_keybindings-for-code-actions) topic where you can learn about different kinds of Code Actions and
how to prioritize them in the case of multiple possible refactorings.
https://code.visualstudio.com/docs/getstarted/keybindings#_detecting-keybinding-conflicts 8/15
22/5/23, 8:01 Visual Studio Code Key Bindings
You can view the default keyboard shortcuts as a JSON file using the command Preferences: Open Default Keyboard Shortcuts (JSON).
Note: The following keys are rendered assuming a standard US keyboard layout. If you use a different keyboard layout, please read below
(/docs/getstarted/keybindings#_keyboard-layouts). You can view the currently active keyboard shortcuts in VS Code in the Command Palette (View -> Command
Palette) or in the Keyboard Shortcuts editor (File > Preferences > Keyboard Shortcuts).
Some commands included below do not have default keyboard shortcuts and so are displayed as unassigned but you can assign your own keybindings.
Basic Editing
https://code.visualstudio.com/docs/getstarted/keybindings#_detecting-keybinding-conflicts 9/15
22/5/23, 8:01 Visual Studio Code Key Bindings
https://code.visualstudio.com/docs/getstarted/keybindings#_detecting-keybinding-conflicts 10/15
22/5/23, 8:01 Visual Studio Code Key Bindings
Navigation
Editor/Window Management
https://code.visualstudio.com/docs/getstarted/keybindings#_detecting-keybinding-conflicts 11/15
22/5/23, 8:01 Visual Studio Code Key Bindings
File Management
Display
https://code.visualstudio.com/docs/getstarted/keybindings#_detecting-keybinding-conflicts 12/15
22/5/23, 8:01 Visual Studio Code Key Bindings
Search
Search Editor
Preferences
Debug
Start F5 workbench.action.debug.start
Continue F5 workbench.action.debug.continue
Pause F6 workbench.action.debug.pause
https://code.visualstudio.com/docs/getstarted/keybindings#_detecting-keybinding-conflicts 13/15
22/5/23, 8:01 Visual Studio Code Key Bindings
Tasks
Extensions
Next steps
Now that you know about our Key binding support, what's next...
Language Support (/docs/languages/overview) - Our Good, Better, Best language grid to see what you can expect
Debugging (/docs/editor/debugging) - This is where VS Code really shines
Node.js (/docs/nodejs/nodejs-tutorial) - End to end Node.js scenario with a sample app
Common questions
How to add a key binding to an action, for example, add Ctrl+D to Delete Lines
Find a rule that triggers the action in the Default Keyboard Shortcuts and write a modified version of it in your keybindings.json file:
How can I add a key binding for only certain file types?
Use the editorLangId context key in your when clause:
https://code.visualstudio.com/docs/getstarted/keybindings#_detecting-keybinding-conflicts 14/15
22/5/23, 8:01 Visual Studio Code Key Bindings
Yes No
5/3/2023
IN THIS ARTICLE
Keymap extensions
Troubleshooting keybindings
Advanced customization
Keyboard rules
Accepted keys
Command arguments
Keyboard layouts
Next steps
Common questions
Tweet
(https://twitter.com/intent/tweet?
this
original_referer=https://code.visualstudio.com/docs/getstarted/keybindings&ref_src=twsrc%5Etfw&text=Visual%20Studio%20Code%20Key%20Bindings&tw_p=tw
link
Subscribe(/feed.xml)
Ask questions(https://stackoverflow.com/questions/tagged/vscode)
Follow @code(https://go.microsoft.com/fwlink/?LinkID=533687)
Request features(https://go.microsoft.com/fwlink/?LinkID=533482)
Report issues(https://www.github.com/Microsoft/vscode/issues)
Watch videos(https://www.youtube.com/channel/UCs5Y5_7XK8HLDX0SLNwkd3w)
(https://www.microsoft.com)
© 2023 Microsoft
https://code.visualstudio.com/docs/getstarted/keybindings#_detecting-keybinding-conflicts 15/15