کلید های میانبر ویژال استدیو

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

Key Command Command id
Ctrl+X Cut line (empty selection) editor.action.clipboardCutAction
Ctrl+C Copy line (empty selection) editor.action.clipboardCopyAction
Ctrl+Shift+K Delete Line editor.action.deleteLines
Ctrl+Enter Insert Line Below editor.action.insertLineAfter
Ctrl+Shift+Enter Insert Line Above editor.action.insertLineBefore
Alt+Down Move Line Down editor.action.moveLinesDownAction
Alt+Up Move Line Up editor.action.moveLinesUpAction
Shift+Alt+Down Copy Line Down editor.action.copyLinesDownAction
Shift+Alt+Up Copy Line Up editor.action.copyLinesUpAction
Ctrl+D Add Selection To Next Find Match editor.action.addSelectionToNextFindMatch
Ctrl+K Ctrl+D Move Last Selection To Next Find Match editor.action.moveSelectionToNextFindMatch
Ctrl+U Undo last cursor operation cursorUndo
Shift+Alt+I Insert cursor at end of each line selected editor.action.insertCursorAtEndOfEachLineSelected
Ctrl+Shift+L Select all occurrences of current selection editor.action.selectHighlights
Ctrl+F2 Select all occurrences of current word editor.action.changeAll
Ctrl+I Select current line expandLineSelection
Ctrl+Alt+Down Insert Cursor Below editor.action.insertCursorBelow
Ctrl+Alt+Up Insert Cursor Above editor.action.insertCursorAbove
Ctrl+Shift+\ Jump to matching bracket editor.action.jumpToBracket
Ctrl+] Indent Line editor.action.indentLines
Ctrl+[ Outdent Line editor.action.outdentLines
Home Go to Beginning of Line cursorHome
End Go to End of Line cursorEnd
Ctrl+End Go to End of File cursorBottom
Ctrl+Home Go to Beginning of File cursorTop
Ctrl+Down Scroll Line Down scrollLineDown
Ctrl+Up Scroll Line Up scrollLineUp
Ctrl+PageDown Scroll Page Down scrollPageDown
Ctrl+PageUp Scroll Page Up scrollPageUp
Ctrl+Shift+[ Fold (collapse) region editor.fold
Ctrl+Shift+] Unfold (uncollapse) region editor.unfold
Ctrl+Shift+Alt+[ Fold (collapse) all regions editor.foldAll
Ctrl+Shift+Alt+] Unfold (uncollapse) all regions editor.unfoldAll
Ctrl+K Ctrl+C Add Line Comment editor.action.addCommentLine
Ctrl+K Ctrl+U Remove Line Comment editor.action.removeCommentLine
Ctrl+/ Toggle Line Comment editor.action.commentLine
Shift+Alt+A Toggle Block Comment editor.action.blockComment
Ctrl+F Find actions.find
Ctrl+H Replace editor.action.startFindReplaceAction
F3 Find Next editor.action.nextMatchFindAction
Shift+F3 Find Previous editor.action.previousMatchFindAction
Alt+C Toggle Find Case Sensitive toggleFindCaseSensitive
Alt+R Toggle Find Regex toggleFindRegex
Alt+W Toggle Find Whole Word toggleFindWholeWord
Ctrl+M Toggle Use of Tab Key for Setting Focus editor.action.toggleTabFocusMode
unassigned Toggle Render Whitespace toggleRenderWhitespace

Rich Languages Editing

Key Command Command id
Ctrl+Space Trigger Suggest editor.action.triggerSuggest
Ctrl+Shift+Space Trigger Parameter Hints editor.action.triggerParameterHints
Shift+Alt+F Format Code editor.action.format
F12 Go to Definition editor.action.goToDeclaration
Alt+F12 Peek Definition editor.action.previewDeclaration
Ctrl+K F12 Open Definition to the Side editor.action.openDeclarationToTheSide
Ctrl+. Quick Fix editor.action.quickFix
Shift+F12 Show References editor.action.referenceSearch.trigger
F2 Rename Symbol editor.action.rename
Ctrl+Shift+. Replace with Next Value editor.action.inPlaceReplace.down
Ctrl+Shift+, Replace with Previous Value editor.action.inPlaceReplace.up
Shift+Alt+Right Expand AST Select editor.action.smartSelect.grow
Shift+Alt+Left Shrink AST Select editor.action.smartSelect.shrink
Ctrl+Shift+X Trim Trailing Whitespace editor.action.trimTrailingWhitespace
Ctrl+K M Change Language Mode workbench.action.editor.changeLanguageMode

Navigation

Key Command Command id
Ctrl+T Show All Symbols workbench.action.showAllSymbols
Ctrl+G Go to Line… workbench.action.gotoLine
Ctrl+P Go to File…, Quick Open workbench.action.quickOpen
Ctrl+Shift+O Go to Symbol… workbench.action.gotoSymbol
Ctrl+Shift+M Show Errors and Warnings workbench.action.showErrorsWarnings
F8 Go to Next Error or Warning editor.action.marker.next
Shift+F8 Go to Previous Error or Warning editor.action.marker.prev
F1 Show All Commands workbench.action.showCommands
Ctrl+Tab Navigate History workbench.action.openPreviousEditor
Alt+Left Go Back workbench.action.navigateBack
Alt+Right Go Forward workbench.action.navigateForward

Editor/Window Management

Key Command Command id
Ctrl+Shift+N New Window workbench.action.newWindow
Ctrl+Shift+W Close Window workbench.action.closeWindow
Ctrl+F4 Close Editor workbench.action.closeActiveEditor
Ctrl+K F Close Folder workbench.action.closeFolder
Ctrl+ Cycle Between Opened Editors workbench.action.cycleEditor
Ctrl+\ Split Editor workbench.action.splitEditor
Ctrl+1 Focus into Left Hand Editor workbench.action.focusFirstEditor
Ctrl+2 Focus into Side Editor workbench.action.focusSecondEditor
Ctrl+3 Focus into Right Hand Editor workbench.action.focusThirdEditor
Ctrl+Alt+Left Focus into Next Editor on the Left workbench.action.focusLeftEditor
Ctrl+Alt+Right Focus into Next Editor on the Right workbench.action.focusRightEditor
Ctrl+K Left Move Active Editor Left workbench.action.moveActiveEditorLeft
Ctrl+K Right Move Active Editor Right workbench.action.moveActiveEditorRight

File Management

Key Command Command id
Ctrl+N New File workbench.action.files.newUntitledFile
Ctrl+O Open File... workbench.action.files.openFile
Ctrl+S Save workbench.action.files.save
unassigned Save All workbench.action.files.saveAll
Ctrl+Shift+S Save As... workbench.action.files.saveAs
Ctrl+K W Close File workbench.files.action.closeFile
Ctrl+K Ctrl+W Close All Files workbench.files.action.closeAllFiles
Ctrl+K Ctrl+Shift+W Close Other Files workbench.files.action.closeOtherFiles
Ctrl+K Enter Add to Working Files workbench.files.action.addToWorkingFiles
Ctrl+K Down Open Next Working File workbench.files.action.openNextWorkingFile
Ctrl+K Up Open Previous Working File workbench.files.action.openPreviousWorkingFile
Ctrl+K P Copy Path of Active File workbench.action.files.copyPathOfActiveFile
Ctrl+K R Reveal Active File in Windows workbench.action.files.revealActiveFileInWindows
Ctrl+K O Show Opened File in New Window workbench.action.files.showOpenedFileInNewWindow
unassigned Compare Opened File With workbench.files.action.compareFileWith

Display

Key Command Command id
F11 Toggle Full Screen workbench.action.toggleFullScreen
Ctrl+= Zoom in workbench.action.zoomIn
Ctrl+- Zoom out workbench.action.zoomOut
Ctrl+B Toggle Sidebar Visibility workbench.action.toggleSidebarVisibility
Ctrl+Shift+D Show Debug workbench.view.debug
Ctrl+Shift+E Show Explorer workbench.view.explorer
Ctrl+Shift+G Show Git workbench.view.git
Ctrl+Shift+F Show Search workbench.view.search
Ctrl+Shift+J Toggle Search Details workbench.action.search.toggleQueryDetails
Ctrl+Shift+C Open New Command Prompt workbench.action.terminal.openNativeConsole
Ctrl+Shift+U Show Output workbench.action.output.toggleOutput
Ctrl+Shift+V Toggle Markdown Preview workbench.action.markdown.togglePreview
Ctrl+K V Open Preview to the Side workbench.action.markdown.openPreviewSideBySide

Preferences

Key Command Command id
unassigned Open User Settings workbench.action.openGlobalSettings
unassigned Open Workspace Settings workbench.action.openWorkspaceSettings
unassigned Open Keyboard Shortcuts workbench.action.openGlobalKeybindings
unassigned Open User Snippets workbench.action.openSnippets
unassigned Select Color Theme workbench.action.selectTheme
unassigned Configure Display Language workbench.action.configureLocale

Debug

Key Command Command id
F9 Toggle Breakpoint editor.debug.action.toggleBreakpoint
F5 Continue workbench.action.debug.continue
F5 Pause workbench.action.debug.start
F11 Step Into workbench.action.debug.stepInto
Shift+F11 Step Out workbench.action.debug.stepOut
F10 Step Over workbench.action.debug.stepOver
Shift+F5 Stop workbench.action.debug.stop
Ctrl+K Ctrl+I Show Hover editor.action.showHover

Tasks

Key Command Command id
Ctrl+Shift+B Run Build Task workbench.action.tasks.build
unassigned Run Test Task workbench.action.tasks.test

Extensions

Key Command Command id
unassigned Install Extension workbench.extensions.action.installExtension
unassigned Show Installed Extensions workbench.extensions.action.listExtensions
unassigned Show Outdated Extensions workbench.extensions.action.listOutdatedExtensions
unassigned Show Extension Recommendations workbench.extensions.action.listSuggestedExtensions

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

Each rule consists of:

  • a required key that describes the pressed keys.
  • an optional when containing a boolean expression that will be evaluated depending on the current context.
  • an optional command containing the identifier of the command to execute.

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:

OS Modifiers
OS X ctrl+, shift+, alt+, cmd+
Windows ctrl+, shift+, alt+, win+
Linux ctrl+, 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, numpad_separator
  • numpad_subtract, numpad_decimal, numpad_divide

Chords are described by separating the two keypresses with a space. E.g.: ctrl+k ctrl+c.

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: https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85)
  • tab for VK_TAB (0x09)
  • ; for VK_OEM_1 (0xBA)
  • = for VK_OEM_PLUS (0xBB)
  • , for VK_OEM_COMMA (0xBC)
  • for VK_OEM_MINUS (0xBD)
  • . for VK_OEM_PERIOD (0xBE)
  • / for VK_OEM_2 (0xBF)
  • ` for VK_OEM_3 (0xC0)
  • [ for VK_OEM_4 (0xDB)
  • \ for VK_OEM_5 (0xDC)
  • ] for VK_OEM_6 (0xDD)
  • 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 Ctrl+*:

render key binding

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 keybindings rules look like when using a French (France) keyboard layout:

keybindings.json guidance

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.

key binding widget

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…

  • Customization – Configure Code the way you want – Themes, Settings and more
  • 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 Ctrl+Shift+O

Key bindings quick outline

Q: How to add a key binding to an action? E.g. 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 User/keybindings.json file:

Q: How to remove a key binding from an action? E.g. Remove Ctrl+Shift+K from Delete Lines

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

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

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

Q: I have modified my key bindings in User/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.

شاید این مطالب را هم دوست داشته باشید

پاسخ دهید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *