快捷键绑定

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 binding for another platform, hover your mouse over the key you are interested in.

Keyboard Shortcuts Editor

Visual Studio Code provides a rich and easy keyboard shortcuts editing experience using Keyboard Shortcuts editor. It lists all available commands with and without keybindings and you can easily change / remove / reset their keybindings using the available actions. It also has a search box on the top that helps you in finding commands or keybindings. You can open this editor by going to the menu under File > Preferences > Keyboard Shortcuts. (Code > Preferences > Keyboard Shortcuts on Mac)

快捷键绑定 - 图1

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.

Keymap Extensions

Keyboard shortcuts are vital to productivity and changing keyboarding habits can be tough. To help with this, File > Preferences > Keymap Extensions 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 of extensions in the Marketplace.

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.

Keyboard Shortcuts Reference

We also have a printable version of these keyboard shortcuts. Help > Keyboard Shortcut Reference displays a condensed PDF version suitable for printing as an easy reference.

Below are links to the three platform-specific versions:

Detecting keybinding conflicts

If you have many extensions installed or you have customized your keyboard shortcuts, you can sometimes have keybinding conflicts where the same keyboard shortcut is mapped to several commands. This can result in confusing behavior, especially if different keybindings are going in and out of scope as you move around the editor.

The Keyboard Shortcuts editor has a context menu command Show Conflicts, which will filter the keybindings based on a keyboard shortcut to display conflicts.

快捷键绑定 - 图2

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.

快捷键绑定 - 图3

Default Keyboard Shortcuts

Note: The following keys are rendered assuming a standard US keyboard layout. If you use a different keyboard layout, please read below. 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).

Basic Editing

KeyCommandCommand id
kb(editor.action.clipboardCutAction)Cut line (empty selection)editor.action.clipboardCutAction
kb(editor.action.clipboardCopyAction)Copy line (empty selection)editor.action.clipboardCopyAction
kb(editor.action.deleteLines)Delete Lineeditor.action.deleteLines
kb(editor.action.insertLineAfter)Insert Line Beloweditor.action.insertLineAfter
kb(editor.action.insertLineBefore)Insert Line Aboveeditor.action.insertLineBefore
kb(editor.action.moveLinesDownAction)Move Line Downeditor.action.moveLinesDownAction
kb(editor.action.moveLinesUpAction)Move Line Upeditor.action.moveLinesUpAction
kb(editor.action.copyLinesDownAction)Copy Line Downeditor.action.copyLinesDownAction
kb(editor.action.copyLinesUpAction)Copy Line Upeditor.action.copyLinesUpAction
kb(editor.action.addSelectionToNextFindMatch)Add Selection To Next Find Matcheditor.action.addSelectionToNextFindMatch
kb(editor.action.moveSelectionToNextFindMatch)Move Last Selection To Next Find Matcheditor.action.moveSelectionToNextFindMatch
kb(cursorUndo)Undo last cursor operationcursorUndo
kb(editor.action.insertCursorAtEndOfEachLineSelected)Insert cursor at end of each line selectededitor.action.insertCursorAtEndOfEachLineSelected
kb(editor.action.selectHighlights)Select all occurrences of current selectioneditor.action.selectHighlights
kb(editor.action.changeAll)Select all occurrences of current wordeditor.action.changeAll
kb(expandLineSelection)Select current lineexpandLineSelection
kb(editor.action.insertCursorBelow)Insert Cursor Beloweditor.action.insertCursorBelow
kb(editor.action.insertCursorAbove)Insert Cursor Aboveeditor.action.insertCursorAbove
kb(editor.action.jumpToBracket)Jump to matching bracketeditor.action.jumpToBracket
kb(editor.action.indentLines)Indent Lineeditor.action.indentLines
kb(editor.action.outdentLines)Outdent Lineeditor.action.outdentLines
kb(cursorHome)Go to Beginning of LinecursorHome
kb(cursorEnd)Go to End of LinecursorEnd
kb(cursorBottom)Go to End of FilecursorBottom
kb(cursorTop)Go to Beginning of FilecursorTop
kb(scrollLineDown)Scroll Line DownscrollLineDown
kb(scrollLineUp)Scroll Line UpscrollLineUp
kb(scrollPageDown)Scroll Page DownscrollPageDown
kb(scrollPageUp)Scroll Page UpscrollPageUp
kb(editor.fold)Fold (collapse) regioneditor.fold
kb(editor.unfold)Unfold (uncollapse) regioneditor.unfold
kb(editor.foldRecursively)Fold (collapse) all subregionseditor.foldRecursively
kb(editor.unfoldRecursively)Unfold (uncollapse) all subregionseditor.unfoldRecursively
kb(editor.foldAll)Fold (collapse) all regionseditor.foldAll
kb(editor.unfoldAll)Unfold (uncollapse) all regionseditor.unfoldAll
kb(editor.action.addCommentLine)Add Line Commenteditor.action.addCommentLine
kb(editor.action.removeCommentLine)Remove Line Commenteditor.action.removeCommentLine
kb(editor.action.commentLine)Toggle Line Commenteditor.action.commentLine
kb(editor.action.blockComment)Toggle Block Commenteditor.action.blockComment
kb(actions.find)Findactions.find
kb(editor.action.startFindReplaceAction)Replaceeditor.action.startFindReplaceAction
kb(editor.action.nextMatchFindAction)Find Nexteditor.action.nextMatchFindAction
kb(editor.action.previousMatchFindAction)Find Previouseditor.action.previousMatchFindAction
kb(editor.action.selectAllMatches)Select All Occurrences of Find Matcheditor.action.selectAllMatches
kb(toggleFindCaseSensitive)Toggle Find Case SensitivetoggleFindCaseSensitive
kb(toggleFindRegex)Toggle Find RegextoggleFindRegex
kb(toggleFindWholeWord)Toggle Find Whole WordtoggleFindWholeWord
kb(editor.action.toggleTabFocusMode)Toggle Use of Tab Key for Setting Focuseditor.action.toggleTabFocusMode
kb(toggleRenderWhitespace)Toggle Render WhitespacetoggleRenderWhitespace
kb(editor.action.toggleWordWrap)Toggle Word Wrapeditor.action.toggleWordWrap

Rich Languages Editing

KeyCommandCommand id
kb(editor.action.triggerSuggest)Trigger Suggesteditor.action.triggerSuggest
kb(editor.action.triggerParameterHints)Trigger Parameter Hintseditor.action.triggerParameterHints
kb(editor.action.formatDocument)Format Documenteditor.action.formatDocument
kb(editor.action.formatSelection)Format Selectioneditor.action.formatSelection
kb(editor.action.goToDeclaration)Go to Definitioneditor.action.goToDeclaration
kb(editor.action.showHover)Show Hovereditor.action.showHover
kb(editor.action.previewDeclaration)Peek Definitioneditor.action.previewDeclaration
kb(editor.action.openDeclarationToTheSide)Open Definition to the Sideeditor.action.openDeclarationToTheSide
kb(editor.action.quickFix)Quick Fixeditor.action.quickFix
kb(editor.action.referenceSearch.trigger)Show Referenceseditor.action.referenceSearch.trigger
kb(editor.action.rename)Rename Symboleditor.action.rename
kb(editor.action.inPlaceReplace.down)Replace with Next Valueeditor.action.inPlaceReplace.down
kb(editor.action.inPlaceReplace.up)Replace with Previous Valueeditor.action.inPlaceReplace.up
kb(editor.action.smartSelect.grow)Expand AST Selecteditor.action.smartSelect.grow
kb(editor.action.smartSelect.shrink)Shrink AST Selecteditor.action.smartSelect.shrink
kb(editor.action.trimTrailingWhitespace)Trim Trailing Whitespaceeditor.action.trimTrailingWhitespace
kb(workbench.action.editor.changeLanguageMode)Change Language Modeworkbench.action.editor.changeLanguageMode

Navigation

KeyCommandCommand id
kb(workbench.action.showAllSymbols)Show All Symbolsworkbench.action.showAllSymbols
kb(workbench.action.gotoLine)Go to Line…workbench.action.gotoLine
kb(workbench.action.quickOpen)Go to File…, Quick Openworkbench.action.quickOpen
kb(workbench.action.gotoSymbol)Go to Symbol…workbench.action.gotoSymbol
kb(workbench.actions.view.problems)Show Problemsworkbench.actions.view.problems
kb(editor.action.marker.next)Go to Next Error or Warningeditor.action.marker.next
kb(editor.action.marker.prev)Go to Previous Error or Warningeditor.action.marker.prev
kb(workbench.action.showCommands)Show All Commandsworkbench.action.showCommands
kb(workbench.action.openPreviousRecentlyUsedEditorInGroup)Navigate Editor Group Historyworkbench.action.openPreviousRecentlyUsedEditorInGroup
kb(workbench.action.navigateBack)Go Backworkbench.action.navigateBack
kb(workbench.action.navigateForward)Go Forwardworkbench.action.navigateForward

Editor/Window Management

KeyCommandCommand id
kb(workbench.action.newWindow)New Windowworkbench.action.newWindow
kb(workbench.action.closeWindow)Close Windowworkbench.action.closeWindow
kb(workbench.action.closeActiveEditor)Close Editorworkbench.action.closeActiveEditor
kb(workbench.action.closeFolder)Close Folderworkbench.action.closeFolder
kb(workbench.action.navigateEditorGroups)Cycle Between Editor Groupsworkbench.action.navigateEditorGroups
kb(workbench.action.splitEditor)Split Editorworkbench.action.splitEditor
kb(workbench.action.focusFirstEditorGroup)Focus into First Editor Groupworkbench.action.focusFirstEditorGroup
kb(workbench.action.focusSecondEditorGroup)Focus into Second Editor Groupworkbench.action.focusSecondEditorGroup
kb(workbench.action.focusThirdEditorGroup)Focus into Third Editor Groupworkbench.action.focusThirdEditorGroup
kb(workbench.action.focusPreviousGroup)Focus into Editor Group on the Leftworkbench.action.focusPreviousGroup
kb(workbench.action.focusNextGroup)Focus into Editor Group on the Rightworkbench.action.focusNextGroup
kb(workbench.action.moveEditorLeftInGroup)Move Editor Leftworkbench.action.moveEditorLeftInGroup
kb(workbench.action.moveEditorRightInGroup)Move Editor Rightworkbench.action.moveEditorRightInGroup
kb(workbench.action.moveActiveEditorGroupLeft)Move Active Editor Group Leftworkbench.action.moveActiveEditorGroupLeft
kb(workbench.action.moveActiveEditorGroupRight)Move Active Editor Group Rightworkbench.action.moveActiveEditorGroupRight
kb(workbench.action.moveEditorToNextGroup)Move Editor into Next Groupworkbench.action.moveEditorToNextGroup
kb(workbench.action.moveEditorToPreviousGroup)Move Editor into Previous Groupworkbench.action.moveEditorToPreviousGroup

File Management

KeyCommandCommand id
kb(workbench.action.files.newUntitledFile)New Fileworkbench.action.files.newUntitledFile
kb(workbench.action.files.openFile)Open File…workbench.action.files.openFile
kb(workbench.action.files.save)Saveworkbench.action.files.save
kb(workbench.action.files.saveAll)Save Allworkbench.action.files.saveAll
kb(workbench.action.files.saveAs)Save As…workbench.action.files.saveAs
kb(workbench.action.closeActiveEditor)Closeworkbench.action.closeActiveEditor
kb(workbench.action.closeOtherEditors)Close Othersworkbench.action.closeOtherEditors
kb(workbench.action.closeEditorsInGroup)Close Groupworkbench.action.closeEditorsInGroup
kb(workbench.action.closeEditorsInOtherGroups)Close Other Groupsworkbench.action.closeEditorsInOtherGroups
kb(workbench.action.closeEditorsToTheLeft)Close Group to Leftworkbench.action.closeEditorsToTheLeft
kb(workbench.action.closeEditorsToTheRight)Close Group to Rightworkbench.action.closeEditorsToTheRight
kb(workbench.action.closeAllEditors)Close Allworkbench.action.closeAllEditors
kb(workbench.action.reopenClosedEditor)Reopen Closed Editorworkbench.action.reopenClosedEditor
kb(workbench.action.keepEditor)Keep Openworkbench.action.keepEditor
kb(workbench.action.openNextRecentlyUsedEditorInGroup)Open Nextworkbench.action.openNextRecentlyUsedEditorInGroup
kb(workbench.action.openPreviousRecentlyUsedEditorInGroup)Open Previousworkbench.action.openPreviousRecentlyUsedEditorInGroup
kb(workbench.action.files.copyPathOfActiveFile)Copy Path of Active Fileworkbench.action.files.copyPathOfActiveFile
kb(workbench.action.files.revealActiveFileInWindows)Reveal Active File in Windowsworkbench.action.files.revealActiveFileInWindows
kb(workbench.action.files.showOpenedFileInNewWindow)Show Opened File in New Windowworkbench.action.files.showOpenedFileInNewWindow
kb(workbench.files.action.compareFileWith)Compare Opened File Withworkbench.files.action.compareFileWith

Display

KeyCommandCommand id
kb(workbench.action.toggleFullScreen)Toggle Full Screenworkbench.action.toggleFullScreen
kb(workbench.action.toggleZenMode)Toggle Zen Modeworkbench.action.toggleZenMode
kb(workbench.action.exitZenMode)Leave Zen Modeworkbench.action.exitZenMode
kb(workbench.action.zoomIn)Zoom inworkbench.action.zoomIn
kb(workbench.action.zoomOut)Zoom outworkbench.action.zoomOut
kb(workbench.action.zoomReset)Reset Zoomworkbench.action.zoomReset
kb(workbench.action.toggleSidebarVisibility)Toggle Sidebar Visibilityworkbench.action.toggleSidebarVisibility
kb(workbench.view.explorer)Show Explorer / Toggle Focusworkbench.view.explorer
kb(workbench.view.search)Show Searchworkbench.view.search
kb(workbench.view.scm)Show Source Controlworkbench.view.scm
kb(workbench.view.debug)Show Debugworkbench.view.debug
kb(workbench.view.extensions)Show Extensionsworkbench.view.extensions
kb(workbench.action.output.toggleOutput)Show Outputworkbench.action.output.toggleOutput
kb(workbench.action.quickOpenView)Quick Open Viewworkbench.action.quickOpenView
kb(workbench.action.terminal.openNativeConsole)Open New Command Promptworkbench.action.terminal.openNativeConsole
kb(markdown.showPreview)Toggle Markdown Previewmarkdown.showPreview
kb(markdown.showPreviewToSide)Open Preview to the Sidemarkdown.showPreviewToSide
kb(workbench.action.terminal.toggleTerminal)Toggle Integrated Terminalworkbench.action.terminal.toggleTerminal
KeyCommandCommand id
kb(workbench.view.search)Show Searchworkbench.view.search
kb(workbench.action.replaceInFiles)Replace in Filesworkbench.action.replaceInFiles
kb(toggleSearchCaseSensitive)Toggle Match CasetoggleSearchCaseSensitive
kb(toggleSearchWholeWord)Toggle Match Whole WordtoggleSearchWholeWord
kb(toggleSearchRegex)Toggle Use Regular ExpressiontoggleSearchRegex
kb(workbench.action.search.toggleQueryDetails)Toggle Search Detailsworkbench.action.search.toggleQueryDetails
kb(search.action.focusNextSearchResult)Focus Next Search Resultsearch.action.focusNextSearchResult
kb(search.action.focusPreviousSearchResult)Focus Previous Search Resultsearch.action.focusPreviousSearchResult
kb(search.history.showNext)Show Next Search Termsearch.history.showNext
kb(search.history.showPrevious)Show Previous Search Termsearch.history.showPrevious

Preferences

KeyCommandCommand id
kb(workbench.action.openGlobalSettings)Open User Settingsworkbench.action.openGlobalSettings
kb(workbench.action.openWorkspaceSettings)Open Workspace Settingsworkbench.action.openWorkspaceSettings
kb(workbench.action.openGlobalKeybindings)Open Keyboard Shortcutsworkbench.action.openGlobalKeybindings
kb(workbench.action.openSnippets)Open User Snippetsworkbench.action.openSnippets
kb(workbench.action.selectTheme)Select Color Themeworkbench.action.selectTheme
kb(workbench.action.configureLocale)Configure Display Languageworkbench.action.configureLocale

Debug

KeyCommandCommand id
kb(editor.debug.action.toggleBreakpoint)Toggle Breakpointeditor.debug.action.toggleBreakpoint
kb(workbench.action.debug.start)Startworkbench.action.debug.start
kb(workbench.action.debug.continue)Continueworkbench.action.debug.continue
kb(workbench.action.debug.run)Start (without debugging)workbench.action.debug.run
kb(workbench.action.debug.pause)Pauseworkbench.action.debug.pause
kb(workbench.action.debug.stepInto)Step Intoworkbench.action.debug.stepInto
kb(workbench.action.debug.stepOut)Step Outworkbench.action.debug.stepOut
kb(workbench.action.debug.stepOver)Step Overworkbench.action.debug.stepOver
kb(workbench.action.debug.stop)Stopworkbench.action.debug.stop
kb(editor.debug.action.showDebugHover)Show Hovereditor.debug.action.showDebugHover

Tasks

KeyCommandCommand id
kb(workbench.action.tasks.build)Run Build Taskworkbench.action.tasks.build
kb(workbench.action.tasks.test)Run Test Taskworkbench.action.tasks.test

Extensions

KeyCommandCommand id
kb(workbench.extensions.action.installExtension)Install Extensionworkbench.extensions.action.installExtension
kb(workbench.extensions.action.showInstalledExtensions)Show Installed Extensionsworkbench.extensions.action.showInstalledExtensions
kb(workbench.extensions.action.listOutdatedExtensions)Show Outdated Extensionsworkbench.extensions.action.listOutdatedExtensions
kb(workbench.extensions.action.showRecommendedExtensions)Show Recommended Extensionsworkbench.extensions.action.showRecommendedExtensions
kb(workbench.extensions.action.showPopularExtensions)Show Popular Extensionsworkbench.extensions.action.showPopularExtensions
kb(workbench.extensions.action.updateAllExtensions)Update All Extensionsworkbench.extensions.action.updateAllExtensions

Advanced customization

All keyboard shortcuts in VS Code can be customized via the keybindings.json file.

  • To configure keyboard shortcuts the way you want, open Keyboard Shortcuts editor and click on the link keybindings.json.
  • This will open the Default Keyboard Shortcuts on the left and your keybindings.json file where you can overwrite the default bindings on the right.
  • The list above isn't exhaustive. More commands may be listed under "Here are other available commands" in Default Keyboard Shortcuts.

Keyboard Rules

The keyboard shortcuts dispatching is done by analyzing a list of rules that are expressed in JSON. Here are some examples:

  1. // Keybindings that are active when the focus is in the editor
  2. { "key": "home", "command": "cursorHome", "when": "editorTextFocus" },
  3. { "key": "shift+home", "command": "cursorHomeSelect", "when": "editorTextFocus" },
  4. // Keybindings that are complementary
  5. { "key": "f5", "command": "workbench.action.debug.continue", "when": "inDebugMode" },
  6. { "key": "f5", "command": "workbench.action.debug.start", "when": "!inDebugMode" },
  7. // Global keybindings
  8. { "key": "ctrl+f", "command": "actions.find" },
  9. { "key": "alt+left", "command": "workbench.action.navigateBack" },
  10. { "key": "alt+right", "command": "workbench.action.navigateForward" },
  11. // Global keybindings using chords (two separate keypress actions)
  12. { "key": "ctrl+k enter", "command": "workbench.action.keepEditor" },
  13. { "key": "ctrl+k ctrl+w", "command": "workbench.action.closeAllEditors" },

Each rule consists of:

  • a key that describes the pressed keys.
  • a command containing the identifier of the command to execute.
  • an optional when clause containing a boolean expression that will be evaluated depending on the current context.Chords (two separate keypress actions) are described by separating the two keypresses with a space. E.g.: kbstyle(ctrl+k ctrl+c).

When a key is pressed:

  • the rules are evaluated from bottom to top.
  • the first rule that matches, both the key and in terms of when, is accepted.
  • no more rules are processed.
  • 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.

Accepted keys

The key is made up of modifiers and the key itself.

The following modifiers are accepted:

PlatformModifiers
Mackbstyle(ctrl+), kbstyle(shift+), kbstyle(alt+), kbstyle(cmd+)
Windowskbstyle(ctrl+), kbstyle(shift+), kbstyle(alt+), kbstyle(win+)
Linuxkbstyle(ctrl+), kbstyle(shift+), kbstyle(alt+), kbstyle(meta+)

The following keys are accepted:

  • kbstyle(f1-f19), kbstyle(a-z), kbstyle(0-9)
  • kbstyle(`), kbstyle(-), kbstyle(=), kbstyle([), kbstyle(]), kbstyle(), kbstyle(;), kbstyle('), kbstyle(,), kbstyle(.), kbstyle(/)
  • kbstyle(left), kbstyle(up), kbstyle(right), kbstyle(down), kbstyle(pageup), kbstyle(pagedown), kbstyle(end), kbstyle(home)
  • kbstyle(tab), kbstyle(enter), kbstyle(escape), kbstyle(space), kbstyle(backspace), kbstyle(delete)
  • kbstyle(pausebreak), kbstyle(capslock), kbstyle(insert)
  • kbstyle(numpad0-numpad9), kbstyle(numpad_multiply), kbstyle(numpad_add), kbstyle(nupad_separator)
  • kbstyle(numpad_subtract), kbstyle(numpad_decimal), kbstyle(numpad_divide)

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 kbstyle(Enter) key to print some text:

  1. { "key": "enter", "command": "type",
  2. "args": { "text": "Hello World" },
  3. "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.

'when' clause contexts

VS Code gives you fine control over when your key bindings are enabled through the optional when clause. If your key binding doesn't have a when clause, the key binding is globally available at all times.

Below are the some of the possible when clause contexts which evaluate to Boolean true/false:

Context nameTrue when
Editor contexts
editorFocusAn editor has focus, either the text or a widget.
editorTextFocusThe text in an editor has focus (cursor is blinking).
editorHasSelectionText is selected in the editor.
editorHasMultipleSelectionsMultiple regions of text are selected (multiple cursors).
editorReadOnlyThe editor is read only.
editorLangIdTrue when the editor's associated language Id matches. Example: "editorLangId == typescript".
textCompareEditorVisibleDiff (compare) view is visible.
Mode contexts
inDebugModeA debug session is running.
inSnippetModeThe editor is in snippet mode.
inQuickOpenThe Quick Open drop-down has focus.
Explorer contexts
explorerViewletVisibleTrue if Explorer view is visible.
explorerViewletFocusTrue if Explorer view has keyboard focus.
filesExplorerFocusTrue if File Explorer section has keyboard focus.
openEditorsFocusTrue if OPEN EDITORS section has keyboard focus.
explorerResourceIsFolderTrue if a folder is selected in the Explorer.
Editor widget contexts
findWidgetVisibleEditor Find widget is visible.
suggestWidgetVisibleSuggestion widget (IntelliSense) is visible.
suggestWidgetMultipleSuggestionsMultiple suggestions are displayed.
renameInputVisibleRename input text box is visible.
referenceSearchVisibleFind All References peek window is open.
inReferenceSearchEditorThe Find All References peek window editor has focus.
config.editor.stablePeekKeep peek editors open (controlled by editor.stablePeek setting).
quickFixWidgetVisibleQuick Fix widget is visible.
parameterHintsVisibleParameter hints are visible (controlled by editor.parameterHints setting).
parameterHintsMultipleSignaturesMultiple parameter hints are displayed.
Integrated terminal contexts
terminalFocusAn integrated terminal has focus.
Global UI contexts
resourceLangIdTrue when the Explorer or editor title language Id matches. Example: "resourceLangId == markdown"
resourceFilenameTrue when the Explorer or editor filename matches. Example: "resourceFilename == gulpfile.js"
globalMessageVisibleMessage box is visible at the top of VS Code.
searchViewletVisibleSearch view is open.
sidebarVisibleSide Bar is displayed.
replaceActiveSearch view Replace text box is open.
Configuration settings contexts
config.editor.minimap.enabledTrue when the setting editor.minimap.enabled is true.

Note: You can use any user or workspace setting that evaluates to a boolean here with the prefix "config.".

The list above isn't exhaustive and you may see some when contexts for specific VS Code UI in the Default Keyboard Shortcuts.

Removing a specific key binding rule

You can write a key binding rule that targets the removal of a specific default key binding. With the keybindings.json, it was always possible to redefine all the key bindings of VS Code, but it can be very difficult to make a small tweak, especially around overloaded keys, such as kbstyle(Tab) or kbstyle(Escape). To remove a specific key binding, add a - to the command and the rule will be a removal rule.

Here is an example:

  1. // In Default Keyboard Shortcuts
  2. ...
  3. { "key": "tab", "command": "tab", "when": ... },
  4. { "key": "tab", "command": "jumpToNextSnippetPlaceholder", "when": ... },
  5. { "key": "tab", "command": "acceptSelectedSuggestion", "when": ... },
  6. ...
  7. // To remove the second rule, for example, add in keybindings.json:
  8. { "key": "tab", "command": "-jumpToNextSnippetPlaceholder" }

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:

  • Reference: Virtual-Key Codes (Windows)
  • kbstyle(tab) for VK_TAB (0x09)
  • kbstyle(;) for VK_OEM_1 (0xBA)
  • kbstyle(=) for VK_OEM_PLUS (0xBB)
  • kbstyle(,) for VK_OEM_COMMA (0xBC)
  • kbstyle(-) for VK_OEM_MINUS (0xBD)
  • kbstyle(.) for VK_OEM_PERIOD (0xBE)
  • kbstyle(/) for VK_OEM_2 (0xBF)
  • kbstyle(`) for VK_OEM_3 (0xC0)
  • kbstyle([) for VK_OEM_4 (0xDB)
  • kbstyle() for VK_OEM_5 (0xDC)
  • kbstyle(]) for VK_OEM_6 (0xDD)
  • kbstyle(') for VK_OEM_7 (0xDE)
  • etc.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 kbstyle(Ctrl+*):

快捷键绑定 - 图4

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 which 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:

快捷键绑定 - 图5

There is also a widget that helps input the key binding rule when editing keybindings.json. To launch the Define Keybinding widget, press kb(editor.action.defineKeybinding). 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 kbstyle(Enter) and a rule snippet will be inserted.

快捷键绑定 - 图6

Note: 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.

Next Steps

Now that you know about our Key binding support, what's next…

  • Language Support - Our Good, Better, Best language grid to see what you can expect
  • Debugging - This is where VS Code really shines
  • Node.js - End to end Node.js scenario with a sample app

Common Questions

Q: How to find out what command is bound to a specific key?

A: In the Default Keyboard Shortcuts, open Quick Outline by pressing kb(workbench.action.gotoSymbol)

快捷键绑定 - 图7

Q: How to add a key binding to an action? For example add Ctrl+D to Delete Lines

A: Find a rule that triggers the action in the Default Keyboard Shortcuts and write a modified version of it in your keybindings.json file:

  1. // Original, in Default Keyboard Shortcuts
  2. { "key": "ctrl+shift+k", "command": "editor.action.deleteLines",
  3. "when": "editorTextFocus" },
  4. // Modified, in User/keybindings.json, Ctrl+D now will also trigger this action
  5. { "key": "ctrl+d", "command": "editor.action.deleteLines",
  6. "when": "editorTextFocus" },

Q: How can I add a key binding for only certain file types?

A: Use the editorLangId context key in your when clause:

  1. { "key": "shift+alt+a", "command": "editor.action.blockComment",
  2. "when": "editorTextFocus && editorLangId == csharp" },

Q: I have modified my key bindings in keybindings.json, why don't they work?

A: The most common problem is a syntax error in the file. Otherwise, try removing the when clause or picking a different key. Unfortunately, at this point, it is a trial and error process.