Visual Studio Code 快捷键


VS code

https://code.visualstudio.com/docs/customization/keybindings


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

Note: The following keys are rendered assuming a standard US keyboard layout. If you use a different keyboard layout, please read below.

Basic Editing

KeyCommandCommand id
Ctrl+XCut line (empty selection)editor.action.clipboardCutAction
Ctrl+CCopy line (empty selection)editor.action.clipboardCopyAction
Ctrl+Shift+KDelete Lineeditor.action.deleteLines
Ctrl+EnterInsert Line Beloweditor.action.insertLineAfter
Ctrl+Shift+EnterInsert Line Aboveeditor.action.insertLineBefore
Alt+DownMove Line Downeditor.action.moveLinesDownAction
Alt+UpMove Line Upeditor.action.moveLinesUpAction
Shift+Alt+DownCopy Line Downeditor.action.copyLinesDownAction
Shift+Alt+UpCopy Line Upeditor.action.copyLinesUpAction
Ctrl+DAdd Selection To Next Find Matcheditor.action.addSelectionToNextFindMatch
Ctrl+K Ctrl+DMove Last Selection To Next Find Matcheditor.action.moveSelectionToNextFindMatch
Ctrl+UUndo last cursor operationcursorUndo
Shift+Alt+IInsert cursor at end of each line selectededitor.action.insertCursorAtEndOfEachLineSelected
Ctrl+Shift+LSelect all occurrences of current selectioneditor.action.selectHighlights
Ctrl+F2Select all occurrences of current wordeditor.action.changeAll
Ctrl+ISelect current lineexpandLineSelection
Ctrl+Alt+DownInsert Cursor Beloweditor.action.insertCursorBelow
Ctrl+Alt+UpInsert Cursor Aboveeditor.action.insertCursorAbove
Ctrl+Shift+\Jump to matching bracketeditor.action.jumpToBracket
Ctrl+]Indent Lineeditor.action.indentLines
Ctrl+[Outdent Lineeditor.action.outdentLines
HomeGo to Beginning of LinecursorHome
EndGo to End of LinecursorEnd
Ctrl+EndGo to End of FilecursorBottom
Ctrl+HomeGo to Beginning of FilecursorTop
Ctrl+DownScroll Line DownscrollLineDown
Ctrl+UpScroll Line UpscrollLineUp
Alt+PageDownScroll Page DownscrollPageDown
Alt+PageUpScroll Page UpscrollPageUp
Ctrl+Shift+[Fold (collapse) regioneditor.fold
Ctrl+Shift+]Unfold (uncollapse) regioneditor.unfold
Ctrl+K Ctrl+[Fold (collapse) all subregionseditor.foldRecursively
Ctrl+K Ctrl+]Unfold (uncollapse) all subregionseditor.unfoldRecursively
Ctrl+K Ctrl+0Fold (collapse) all regionseditor.foldAll
Ctrl+K Ctrl+JUnfold (uncollapse) all regionseditor.unfoldAll
Ctrl+K Ctrl+CAdd Line Commenteditor.action.addCommentLine
Ctrl+K Ctrl+URemove Line Commenteditor.action.removeCommentLine
Ctrl+/Toggle Line Commenteditor.action.commentLine
Shift+Alt+AToggle Block Commenteditor.action.blockComment
Ctrl+FFindactions.find
Ctrl+HReplaceeditor.action.startFindReplaceAction
F3Find Nexteditor.action.nextMatchFindAction
Shift+F3Find Previouseditor.action.previousMatchFindAction
Alt+EnterSelect All Occurences of Find Matcheditor.action.selectAllMatches
Alt+CToggle Find Case SensitivetoggleFindCaseSensitive
Alt+RToggle Find RegextoggleFindRegex
Alt+WToggle Find Whole WordtoggleFindWholeWord
Ctrl+MToggle Use of Tab Key for Setting Focuseditor.action.toggleTabFocusMode
unassignedToggle Render WhitespacetoggleRenderWhitespace

Rich Languages Editing

KeyCommandCommand id
Ctrl+SpaceTrigger Suggesteditor.action.triggerSuggest
Ctrl+Shift+SpaceTrigger Parameter Hintseditor.action.triggerParameterHints
Shift+Alt+FFormat Codeeditor.action.format
F12Go to Definitioneditor.action.goToDeclaration
Alt+F12Peek Definitioneditor.action.previewDeclaration
Ctrl+K F12Open Definition to the Sideeditor.action.openDeclarationToTheSide
Ctrl+.Quick Fixeditor.action.quickFix
Shift+F12Show Referenceseditor.action.referenceSearch.trigger
F2Rename Symboleditor.action.rename
Ctrl+Shift+.Replace with Next Valueeditor.action.inPlaceReplace.down
Ctrl+Shift+,Replace with Previous Valueeditor.action.inPlaceReplace.up
Shift+Alt+RightExpand AST Selecteditor.action.smartSelect.grow
Shift+Alt+LeftShrink AST Selecteditor.action.smartSelect.shrink
Ctrl+K Ctrl+XTrim Trailing Whitespaceeditor.action.trimTrailingWhitespace
Ctrl+K MChange Language Modeworkbench.action.editor.changeLanguageMode

Navigation

KeyCommandCommand id
Ctrl+TShow All Symbolsworkbench.action.showAllSymbols
Ctrl+GGo to Line...workbench.action.gotoLine
Ctrl+PGo to File..., Quick Openworkbench.action.quickOpen
Ctrl+Shift+OGo to Symbol...workbench.action.gotoSymbol
Ctrl+Shift+MShow Problemsworkbench.actions.view.problems
F8Go to Next Error or Warningeditor.action.marker.next
Shift+F8Go to Previous Error or Warningeditor.action.marker.prev
Ctrl+Shift+PShow All Commandsworkbench.action.showCommands
Ctrl+Shift+TabNavigate Editor Group Historyworkbench.action.openPreviousRecentlyUsedEditorInGroup
Alt+LeftGo Backworkbench.action.navigateBack
Alt+RightGo Forwardworkbench.action.navigateForward

Editor/Window Management

KeyCommandCommand id
Ctrl+Shift+NNew Windowworkbench.action.newWindow
Ctrl+WClose Windowworkbench.action.closeWindow
Ctrl+F4Close Editorworkbench.action.closeActiveEditor
Ctrl+K FClose Folderworkbench.action.closeFolder
unassignedCycle Between Editor Groupsworkbench.action.navigateEditorGroups
Ctrl+\Split Editorworkbench.action.splitEditor
Ctrl+1Focus into Left Editor Groupworkbench.action.focusFirstEditorGroup
Ctrl+2Focus into Side Editor Groupworkbench.action.focusSecondEditorGroup
Ctrl+3Focus into Right Editor Groupworkbench.action.focusThirdEditorGroup
Ctrl+K Ctrl+LeftFocus into Editor Group on the Leftworkbench.action.focusPreviousGroup
Ctrl+K Ctrl+RightFocus into Editor Group on the Rightworkbench.action.focusNextGroup
Ctrl+K LeftMove Active Editor Group Leftworkbench.action.moveActiveEditorGroupLeft
Ctrl+K RightMove Active Editor Group Rightworkbench.action.moveActiveEditorGroupRight

File Management

KeyCommandCommand id
Ctrl+NNew Fileworkbench.action.files.newUntitledFile
Ctrl+OOpen File...workbench.action.files.openFile
Ctrl+SSaveworkbench.action.files.save
unassignedSave Allworkbench.action.files.saveAll
Ctrl+Shift+SSave As...workbench.action.files.saveAs
Ctrl+F4Closeworkbench.action.closeActiveEditor
unassignedClose Othersworkbench.action.closeOtherEditors
Ctrl+K WClose Groupworkbench.action.closeEditorsInGroup
unassignedClose Other Groupsworkbench.action.closeEditorsInOtherGroups
unassignedClose Group to Leftworkbench.action.closeEditorsToTheLeft
unassignedClose Group to Rightworkbench.action.closeEditorsToTheRight
Ctrl+K Ctrl+WClose Allworkbench.action.closeAllEditors
Ctrl+K EnterKeep Openworkbench.action.keepEditor
Ctrl+TabOpen Nextworkbench.action.openNextRecentlyUsedEditorInGroup
Ctrl+Shift+TabOpen Previousworkbench.action.openPreviousRecentlyUsedEditorInGroup
Ctrl+K PCopy Path of Active Fileworkbench.action.files.copyPathOfActiveFile
Ctrl+K RReveal Active File in Windowsworkbench.action.files.revealActiveFileInWindows
Ctrl+K OShow Opened File in New Windowworkbench.action.files.showOpenedFileInNewWindow
unassignedCompare Opened File Withworkbench.files.action.compareFileWith

Display

KeyCommandCommand id
F11Toggle Full Screenworkbench.action.toggleFullScreen
Ctrl+=Zoom inworkbench.action.zoomIn
Ctrl+-Zoom outworkbench.action.zoomOut
unassignedReset Zoomworkbench.action.zoomReset
Ctrl+BToggle Sidebar Visibilityworkbench.action.toggleSidebarVisibility
Ctrl+Shift+DShow Debugworkbench.view.debug
Ctrl+Shift+EShow Explorer / Toggle Focusworkbench.view.explorer
Ctrl+Shift+GShow Gitworkbench.view.git
Ctrl+Shift+FShow Searchworkbench.view.search
Ctrl+Shift+HReplace in Filesworkbench.action.replaceInFiles
Ctrl+Shift+XShow Extensionsworkbench.view.extensions
Ctrl+Shift+JToggle Search Detailsworkbench.action.search.toggleQueryDetails
Ctrl+Shift+COpen New Command Promptworkbench.action.terminal.openNativeConsole
Ctrl+Shift+UShow Outputworkbench.action.output.toggleOutput
Ctrl+Shift+VToggle Markdown Previewmarkdown.showPreview
Ctrl+K VOpen Preview to the Sidemarkdown.showPreviewToSide
Ctrl+`Toggle Integrated Terminalworkbench.action.terminal.toggleTerminal

Preferences

KeyCommandCommand id
unassignedOpen User Settingsworkbench.action.openGlobalSettings
unassignedOpen Workspace Settingsworkbench.action.openWorkspaceSettings
unassignedOpen Keyboard Shortcutsworkbench.action.openGlobalKeybindings
unassignedOpen User Snippetsworkbench.action.openSnippets
unassignedSelect Color Themeworkbench.action.selectTheme
unassignedConfigure Display Languageworkbench.action.configureLocale

Debug

KeyCommandCommand id
F9Toggle Breakpointeditor.debug.action.toggleBreakpoint
F5Continueworkbench.action.debug.continue
F5Pauseworkbench.action.debug.start
F11Step Intoworkbench.action.debug.stepInto
Shift+F11Step Outworkbench.action.debug.stepOut
F10Step Overworkbench.action.debug.stepOver
Shift+F5Stopworkbench.action.debug.stop
Ctrl+K Ctrl+IShow Hovereditor.action.showHover

Tasks

KeyCommandCommand id
Ctrl+Shift+BRun Build Taskworkbench.action.tasks.build
unassignedRun Test Taskworkbench.action.tasks.test

Extensions

KeyCommandCommand id
unassignedInstall Extensionworkbench.extensions.action.installExtension
unassignedShow Installed Extensionsworkbench.extensions.action.showInstalledExtensions
unassignedShow Outdated Extensionsworkbench.extensions.action.listOutdatedExtensions
unassignedShow Recommended Extensionsworkbench.extensions.action.showRecommendedExtensions
unassignedShow Popular Extensionsworkbench.extensions.action.showPopularExtensions

Customizing Shortcuts

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

  • To configure keyboard shortcuts the way you want, go to the menu under File > Preferences > Keyboard Shortcuts. (Code > Preferences > Keyboard Shortcuts on Mac)
  • This will open the Default Keyboard Shortcuts on the left and your User/keybindings.json file where you can overwrite the default bindings on the right.

Keyboard Rules

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

// Keybindings that are active when the focus is in the editor
{ "key": "home",            "command": "cursorHome",                  "when": "editorTextFocus" },
{ "key": "shift+home",      "command": "cursorHomeSelect",            "when": "editorTextFocus" },

// Keybindings that are complementary
{ "key": "f5",              "command": "workbench.action.debug.continue", "when": "inDebugMode" },
{ "key": "f5",              "command": "workbench.action.debug.start",    "when": "!inDebugMode" },

// Global keybindings
{ "key": "ctrl+f",          "command": "actions.find" },
{ "key": "alt+left",        "command": "workbench.action.navigateBack" },
{ "key": "alt+right",       "command": "workbench.action.navigateForward" },

// Global keybindings using chords (two separate keypress actions)
{ "key": "ctrl+k enter",    "command": "workbench.action.keepEditor" },
{ "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.: 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 User/keybindings.json rules are appended at runtime to the bottom of the default rules, thus allowing them to overwrite the default rules. The User/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:

OSModifiers
OS Xctrl+, shift+, alt+, cmd+
Windowsctrl+, shift+, alt+, win+
Linuxctrl+, shift+, alt+, meta+

The following keys are accepted:

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

when Clause Contexts

VS Code gives you fine control over when your key bindings are enabled through the optional when clause. If you 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".
Mode contexts 
inDebugModeA debug session is running.
inSnippetModeThe editor is in snippet mode.
inQuickOpenThe Quick Open dropdown has focus.
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"
globalMessageVisibleMessage box is visible at the top of VS Code.
searchViewletVisibleSearch view is open.
replaceActiveSearch view Replace text box is open.

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 Tab or Escape. To remove a specific key binding, simply add a - to the command and the rule will be a removal rule.

Here is an example:

// In Default Keyboard Shortcuts
...
{ "key": "tab", "command": "tab", "when": ... },
{ "key": "tab", "command": "editor.emmet.action.expandAbbreviation", "when": ... },
{ "key": "tab", "command": "jumpToNextSnippetPlaceholder", "when": ... },
{ "key": "tab", "command": "acceptQuickFixSuggestion", "when": ... },
{ "key": "tab", "command": "acceptSelectedSuggestion", "when": ... },
...

// To remove the second rule, for example, add in keybindings.json:
{ "key": "tab", "command": "-editor.emmet.action.expandAbbreviation" }


  • 0
    点赞
  • 1
    收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:编程工作室 设计师:CSDN官方博客 返回首页
评论
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值