Visual Studio Code 的快捷键绑定

Visual Studio Code 允许您直接从键盘执行大多数任务。本页面列出了默认的绑定(键盘快捷键),并描述了如何更新它们。

注意: 如果您在Mac上访问此页面,您将看到Mac的键绑定。如果您使用Windows或Linux访问,您将看到该平台的键。如果您需要另一个平台的键绑定,请将鼠标悬停在您感兴趣的键上。

键盘快捷键编辑器

VS Code 提供了一个丰富的键盘快捷键编辑体验,通过键盘快捷键编辑器。该编辑器列出了所有可用的命令,无论是否有键绑定,并允许您使用可用的操作更改/删除/重置它们的键绑定。您可以使用搜索框来查找命令或键绑定。您可以通过菜单中的 文件 > 首选项 > 键盘快捷键 或使用 首选项:打开键盘快捷键 命令 (⌘K ⌘S (Windows, Linux Ctrl+K Ctrl+S)) 打开此编辑器。

键盘快捷键

最重要的是,您可以根据您的键盘布局查看快捷键。例如,在美国键盘布局中的快捷键 Cmd+\ 在布局更改为德语时,将显示为 Ctrl+Shift+Alt+Cmd+7。输入快捷键的对话框将根据您的键盘布局分配正确且所需的快捷键。

要进行更高级的键盘快捷键自定义,请阅读高级自定义

自定义UI操作的快捷键

您可以快速自定义用户界面操作的键绑定。右键单击工作台中的任何操作项,然后选择自定义键绑定。如果操作有when子句,它会自动包含在内,使您更容易根据需要设置键绑定。

键映射扩展

键盘快捷键对提高生产力至关重要,而改变键盘习惯可能很困难。为了帮助解决这个问题,文件 > 首选项 > 从...迁移键盘快捷键 显示了一个流行的键映射扩展列表。这些扩展修改了VS Code的快捷键,以匹配其他编辑器的快捷键,这样你就不需要学习新的键盘快捷键。市场里还有一个键映射类别的扩展。

提示:点击上面的扩展磁贴以阅读描述和评论,以决定哪个扩展最适合您。在Marketplace中查看更多。

键盘快捷键参考

我们还提供了这些键盘快捷键的可打印版本。帮助 > 键盘快捷键参考 显示了一个适合打印的简化PDF版本,便于快速参考。

以下是三个平台特定版本的链接(美国英语键盘):

检测键绑定冲突

如果你安装了许多扩展程序或者你自定义了你的键盘快捷键,有时你可能会遇到键绑定冲突,即同一个键盘快捷键被映射到多个命令。这可能会导致混乱的行为,特别是当你在编辑器中移动时,不同的键绑定进入和退出作用域。

键盘快捷键编辑器有一个上下文菜单命令显示相同键绑定,它将根据键盘快捷键过滤键绑定以显示冲突。

显示键绑定冲突菜单

选择一个你认为键绑定过载的命令,你可以查看是否定义了多个命令、键绑定的来源以及它们何时处于活动状态。

显示键绑定冲突结果

故障排除键绑定

要解决快捷键绑定问题,您可以执行命令Developer: Toggle Keyboard Shortcuts Troubleshooting。这将激活已分发的快捷键的日志记录,并会打开一个带有相应日志文件的输出面板。

然后您可以按下您想要的键绑定,并检查VS Code检测到的键盘快捷键以及调用的命令。

例如,在macOS上的代码编辑器中按下cmd+/时,日志输出将是:

[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-in.

第一个keydown事件是针对MetaLeft键(cmd)的,无法分发。第二个keydown事件是针对Slash键(/)的,并以meta+[Slash]的形式分发。有两个键绑定条目从meta+[Slash]映射而来,匹配的是命令editor.action.commentLine,该命令具有when条件editorTextFocus && !editorReadonly,并且是一个内置的键绑定条目。

查看修改后的键绑定

你可以在VS Code的键盘快捷键编辑器中查看任何用户修改的键盘快捷键,通过更多操作...)菜单中的显示用户键绑定命令。这将应用@source:user过滤器到键盘快捷键编辑器(来源是'用户')。

默认键盘快捷键

高级定制

VS Code 中的所有键盘快捷键都可以通过 keybindings.json 文件进行自定义,您可以在其中覆盖 默认键盘快捷键

要打开keybindings.json文件:

  • 打开键盘快捷键编辑器,然后选择编辑器标题栏右侧的打开键盘快捷键(JSON)按钮。

    打开键盘快捷键 JSON 按钮 在命令面板中 (⇧⌘P (Windows, Linux Ctrl+Shift+P)).

键盘规则

每条规则包括:

  • 一个 key,用于描述按下的键。
  • 一个包含要执行的命令标识符的 command
  • 一个可选的 when 子句,包含一个布尔表达式,该表达式将根据当前的上下文进行评估。

和弦(两个独立的按键操作)通过用空格分隔两个按键来描述。例如,Ctrl+K Ctrl+C

当按下键时:

  • 规则从底部顶部进行评估。
  • 匹配的第一条规则,无论是key还是when,都会被接受。
  • 不再处理更多规则。
  • 如果找到规则并且设置了command,则执行command

额外的keybindings.json规则在运行时附加到默认规则的底部,从而允许它们覆盖默认规则。VS Code会监视keybindings.json文件,因此在VS Code运行时编辑它将在运行时更新规则。

键盘快捷键的调度是通过分析以JSON格式表达的规则列表来完成的。以下是一些示例:

// 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" },

接受的键

key 由修饰符和键本身组成。

以下修饰符被接受:

Platform Modifiers
macOS Ctrl+, Shift+, Alt+, Cmd+
Windows Ctrl+, Shift+, Alt+, Win+
Linux Ctrl+, Shift+, Alt+, Meta+

以下键被接受:

  • f1-f19, a-z, 0-9
  • `, -, =, [, ], \, ;, ', ,, ., /
  • , , , , 上一页, 下一页, 结束, 首页
  • tab, enter, escape, space, backspace, delete
  • pausebreak, capslock, insert
  • 数字键盘0-9, 数字键盘乘号, 数字键盘加号, 数字键盘分隔符
  • numpad_subtract, numpad_decimal, numpad_divide

命令参数

你可以使用参数调用命令。如果你经常对特定文件或文件夹执行相同的操作,这将非常有用。你可以添加自定义键盘快捷键来精确执行你想要的命令。

以下是一个覆盖 Enter 键以打印一些文本的示例:

{
  "key": "enter",
  "command": "type",
  "args": { "text": "Hello World" },
  "when": "editorTextFocus"
}

type 命令将接收 {"text": "Hello World"} 作为其第一个参数,并将 "Hello World" 添加到文件中,而不是生成默认命令。

有关接受参数的命令的更多信息,请参阅内置命令

运行多个命令

可以创建一个键绑定,使用命令runCommands依次运行多个其他命令。

  1. 运行几个不带参数的命令:将当前行复制到下一行,将当前行标记为注释,将光标移动到复制的行
{
  "key": "ctrl+alt+c",
  "command": "runCommands",
  "args": {
    "commands": [
      "editor.action.copyLinesDownAction",
      "cursorUp",
      "editor.action.addCommentLine",
      "cursorDown"
    ]
  }
},
  1. 也可以向命令传递参数:创建一个新的无标题的TypeScript文件并插入自定义代码片段
{
  "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}"
        }
      }
    ]
  }
},

请注意,由runCommands运行的命令会将"args"的值作为第一个参数接收。因此,在上面的示例中,workbench.action.files.newUntitledFile接收{"languageId": "typescript" }作为其第一个也是唯一的参数。

要传递多个参数,需要将"args"作为数组:

{
  "key": "ctrl+shift+e",
  "command": "runCommands",
  "args": {
    "commands": [
      {
        // command invoked with 2 arguments: vscode.executeCommand("myCommand", "arg1", "arg2")
        "command": "myCommand",
        "args": ["arg1", "arg2"]
      }
    ]
  }
}

要将数组作为第一个参数传递,需要将数组包装在另一个数组中:"args": [ [1, 2, 3] ]

移除特定的键绑定规则

你可以编写一个键绑定规则,目标是移除特定的默认键绑定。使用keybindings.json,总是可以重新定义VS Code的所有键绑定,但进行小的调整可能会很困难,特别是对于像TabEscape这样的重载键。要移除特定的键绑定,可以在command前添加一个-,这样规则就会变成移除规则。

这是一个示例:

// In Default Keyboard Shortcuts
...
{ "key": "tab", "command": "tab", "when": ... },
{ "key": "tab", "command": "jumpToNextSnippetPlaceholder", "when": ... },
{ "key": "tab", "command": "acceptSelectedSuggestion", "when": ... },
...

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

要使用空操作覆盖特定的键绑定规则,您可以指定一个空命令:

// To override and disable any `tab` keybinding, for example, add in keybindings.json:
{ "key": "tab", "command": "" }

键盘布局

注意: 本节仅与键绑定相关,与在编辑器中输入无关。

上面的键是虚拟键的字符串表示,按下它们时不一定与生成的字符相关。更准确地说:

  • 参考:虚拟键码 (Windows)
  • tab 对应 VK_TAB (0x09)
  • ; 对应 VK_OEM_1 (0xBA)
  • = 对应 VK_OEM_PLUS (0xBB)
  • , 对应 VK_OEM_COMMA (0xBC)
  • - 对应 VK_OEM_MINUS (0xBD)
  • . 对应 VK_OEM_PERIOD (0xBE)
  • / 对应 VK_OEM_2 (0xBF)
  • ` 对应 VK_OEM_3 (0xC0)
  • [ 对应 VK_OEM_4 (0xDB)
  • \ 对应 VK_OEM_5 (0xDC)
  • ] 对应 VK_OEM_6 (0xDD)
  • ' 对应 VK_OEM_7 (0xDE)
  • 等等。

不同的键盘布局通常会重新定位上述虚拟键或改变按下时产生的字符。当使用不同于标准美式键盘的布局时,Visual Studio Code 会执行以下操作:

所有的键绑定都在用户界面中使用当前系统的键盘布局进行渲染。例如,当使用法语(法国)键盘布局时,Split Editor现在被渲染为Ctrl+*

渲染键绑定

在编辑keybindings.json时,VS Code 会高亮显示误导性的键绑定,这些键绑定在文件中以标准美国键盘布局下产生的字符表示,但在当前系统的键盘布局下需要按下不同标签的键。例如,以下是使用法语(法国)键盘布局时默认键盘快捷键规则的样子:

keybindings.json 指南

还有一个工具可以帮助在编辑keybindings.json时输入键绑定规则。要启动定义键绑定工具,请按⌘K ⌘K (Windows, Linux Ctrl+K Ctrl+K)。该工具会监听按键并在文本框中显示序列化的JSON表示,并在其下方显示VS Code在当前键盘布局下检测到的按键。一旦你输入了所需的键组合,你可以按Enter,然后会插入一个规则片段。

快捷键绑定小部件

注意: 在Linux上,Visual Studio Code在启动时会检测您当前的键盘布局并缓存此信息。为了获得良好的体验,如果您更改了键盘布局,我们建议重新启动VS Code。

键盘布局无关的绑定

使用扫描码,可以定义不随键盘布局变化而变化的键绑定。例如:

{ "key": "cmd+[Slash]", "command": "editor.action.commentLine", "when": "editorTextFocus" }

接受的扫描代码:

  • [F1]-[F19], [KeyA]-[KeyZ], [Digit0]-[Digit9]
  • [反引号], [减号], [等号], [左括号], [右括号], [反斜杠], [分号], [引号], [逗号], [句号], [斜杠]
  • [左箭头], [上箭头], [右箭头], [下箭头], [向上翻页], [向下翻页], [结束], [首页]
  • [Tab], [Enter], [Escape], [空格键], [退格键], [删除键]
  • [暂停], [大写锁定], [插入]
  • [Numpad0]-[Numpad9], [NumpadMultiply], [NumpadAdd], [NumpadComma]
  • [NumpadSubtract], [NumpadDecimal], [NumpadDivide]

when 子句上下文

VS Code 通过可选的 when 子句,让您可以精细控制何时启用您的键绑定。如果您的键绑定没有 when 子句,则该键绑定始终全局可用。when 子句会评估为布尔值 true 或 false,以启用键绑定。

VS Code 根据 UI 中可见和活动的元素设置各种上下文键和特定值。例如,内置的 启动调试 命令具有键盘快捷键 F5,该快捷键仅在存在适当的调试器(上下文 debuggersAvailable 为 true)且编辑器未处于调试模式(上下文 inDebugMode 为 false)时启用:

在键盘快捷键编辑器中开始调试when子句

你也可以直接在默认键绑定JSON中查看键绑定的when子句(首选项:打开默认键盘快捷键(JSON)):

{ "key": "f5",  "command": "workbench.action.debug.start",
                   "when": "debuggersAvailable && !inDebugMode" },

条件运算符

对于when子句的条件表达式,以下条件运算符对于键绑定非常有用:

Operator Symbol Example
Equality == "editorLangId == typescript"
Inequality != "resourceExtname != .js"
Or || "isLinux||isWindows"
And && "textInputFocus && !editorReadonly"
Matches =~ "resourceScheme =~ /^untitled$|^file$/"

你可以在when clause contexts参考中找到when子句条件运算符的完整列表。

可用上下文

你可以在when 子句上下文参考中找到一些可用的when子句上下文。

该列表并不详尽,您可以通过在键盘快捷键编辑器(首选项:打开键盘快捷键)中搜索和过滤,或查看默认键绑定JSON文件(首选项:打开默认键盘快捷键(JSON))来找到其他when子句上下文。

自定义重构快捷键

editor.action.codeAction 命令允许您为特定的重构(代码操作)配置快捷键。例如,下面的快捷键触发了提取函数重构代码操作:

{
  "key": "ctrl+shift+r ctrl+e",
  "command": "editor.action.codeAction",
  "args": {
    "kind": "refactor.extract.function"
  }
}

这在重构主题中有深入介绍,您可以了解不同类型的代码操作以及在有多种可能的重构时如何优先处理它们。

默认键盘快捷键

你可以在VS Code的键盘快捷键编辑器中查看所有默认的键盘快捷键,通过更多操作...)菜单中的显示默认键绑定命令。这将应用@source:default过滤器到键盘快捷键编辑器(来源是'默认')。

默认键盘快捷键

您可以使用命令Preferences: Open Default Keyboard Shortcuts (JSON)将默认的键盘快捷键查看为JSON文件。

注意: 以下按键是基于标准美国键盘布局显示的。如果您使用不同的键盘布局,请阅读下方内容。您可以在VS Code的命令面板查看 -> 命令面板)或键盘快捷键编辑器(文件 > 首选项 > 键盘快捷键)中查看当前激活的键盘快捷键。

下面包含的一些命令没有默认的键盘快捷键,因此显示为未分配,但您可以分配自己的快捷键。

基本编辑

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

丰富的语言编辑

Command Key Command id
Trigger Suggest ⌃Space (Windows, Linux Ctrl+Space) editor.action.triggerSuggest
Trigger Parameter Hints ⇧⌘Space (Windows, Linux Ctrl+Shift+Space) editor.action.triggerParameterHints
Format Document ⇧⌥F (Windows Shift+Alt+F, Linux Ctrl+Shift+I) editor.action.formatDocument
Format Selection ⌘K ⌘F (Windows, Linux Ctrl+K Ctrl+F) editor.action.formatSelection
Go to Definition F12 editor.action.revealDefinition
Show Hover ⌘K ⌘I (Windows, Linux Ctrl+K Ctrl+I) editor.action.showHover
Peek Definition ⌥F12 (Windows Alt+F12, Linux Ctrl+Shift+F10) editor.action.peekDefinition
Open Definition to the Side ⌘K F12 (Windows, Linux Ctrl+K F12) editor.action.revealDefinitionAside
Quick Fix ⌘. (Windows, Linux Ctrl+.) editor.action.quickFix
Go to References ⇧F12 (Windows, Linux Shift+F12) editor.action.goToReferences
Rename Symbol F2 editor.action.rename
Replace with Next Value ⇧⌘. (Windows, Linux Ctrl+Shift+.) editor.action.inPlaceReplace.down
Replace with Previous Value ⇧⌘, (Windows, Linux Ctrl+Shift+,) editor.action.inPlaceReplace.up
Expand AST Selection ⌃⇧⌘→ (Windows, Linux Shift+Alt+Right) editor.action.smartSelect.expand
Shrink AST Selection ⌃⇧⌘← (Windows, Linux Shift+Alt+Left) editor.action.smartSelect.shrink
Trim Trailing Whitespace ⌘K ⌘X (Windows, Linux Ctrl+K Ctrl+X) editor.action.trimTrailingWhitespace
Change Language Mode ⌘K M (Windows, Linux Ctrl+K M) workbench.action.editor.changeLanguageMode

导航

Command Key Command id
Show All Symbols ⌘T (Windows, Linux Ctrl+T) workbench.action.showAllSymbols
Go to Line... ⌃G (Windows, Linux Ctrl+G) workbench.action.gotoLine
Go to File..., Quick Open ⌘P (Windows, Linux Ctrl+P) workbench.action.quickOpen
Go to Symbol... ⇧⌘O (Windows, Linux Ctrl+Shift+O) workbench.action.gotoSymbol
Show Problems ⇧⌘M (Windows, Linux Ctrl+Shift+M) workbench.actions.view.problems
Go to Next Error or Warning F8 editor.action.marker.nextInFiles
Go to Previous Error or Warning ⇧F8 (Windows, Linux Shift+F8) editor.action.marker.prevInFiles
Show All Commands ⇧⌘P (Windows, Linux Ctrl+Shift+P) or F1 workbench.action.showCommands
Navigate Editor Group History ⌃Tab (Windows, Linux Ctrl+Tab) workbench.action.quickOpenPreviousRecentlyUsedEditorInGroup
Go Back ⌃- (Windows Alt+Left, Linux Ctrl+Alt+-) workbench.action.navigateBack
Go back in Quick Input ⌃- (Windows Alt+Left, Linux Ctrl+Alt+-) workbench.action.quickInputBack
Go Forward ⌃⇧- (Windows Alt+Right, Linux Ctrl+Shift+-) workbench.action.navigateForward
Focus Breadcrumbs ⇧⌘; (Windows, Linux Ctrl+Shift+;) breadcrumbs.focus
Focus and Select Breadcrumbs ⇧⌘. (Windows, Linux Ctrl+Shift+.) breadcrumbs.focusAndSelect

编辑器/窗口管理

Command Key Command id
New Window ⇧⌘N (Windows, Linux Ctrl+Shift+N) workbench.action.newWindow
Close Window ⌘W (Windows, Linux Alt+F4) workbench.action.closeWindow
Close Editor ⌘W (Windows Ctrl+F4, Linux Ctrl+W) workbench.action.closeActiveEditor
Close Folder ⌘K F (Windows, Linux Ctrl+K F) workbench.action.closeFolder
Cycle Between Editor Groups workbench.action.navigateEditorGroups
Split Editor ⌘\ (Windows, Linux Ctrl+\) workbench.action.splitEditor
Focus into First Editor Group ⌘1 (Windows, Linux Ctrl+1) workbench.action.focusFirstEditorGroup
Focus into Second Editor Group ⌘2 (Windows, Linux Ctrl+2) workbench.action.focusSecondEditorGroup
Focus into Third Editor Group ⌘3 (Windows, Linux Ctrl+3) workbench.action.focusThirdEditorGroup
Focus into Editor Group on the Left workbench.action.focusPreviousGroup
Focus into Editor Group on the Right workbench.action.focusNextGroup
Move Editor Left ⌘K ⇧⌘← (Windows, Linux Ctrl+Shift+PageUp) workbench.action.moveEditorLeftInGroup
Move Editor Right ⌘K ⇧⌘→ (Windows, Linux Ctrl+Shift+PageDown) workbench.action.moveEditorRightInGroup
Move Active Editor Group Left ⌘K ← (Windows, Linux Ctrl+K Left) workbench.action.moveActiveEditorGroupLeft
Move Active Editor Group Right ⌘K → (Windows, Linux Ctrl+K Right) workbench.action.moveActiveEditorGroupRight
Move Editor into Next Group ⌃⌘→ (Windows, Linux Ctrl+Alt+Right) workbench.action.moveEditorToNextGroup
Move Editor into Previous Group ⌃⌘← (Windows, Linux Ctrl+Alt+Left) workbench.action.moveEditorToPreviousGroup

文件管理

Command Key Command id
New File ⌘N (Windows, Linux Ctrl+N) workbench.action.files.newUntitledFile
Open File... ⌘O (Windows, Linux Ctrl+O) workbench.action.files.openFile
Save ⌘S (Windows, Linux Ctrl+S) workbench.action.files.save
Save All ⌥⌘S (Windows Ctrl+K S, Linux ) saveAll
Save As... ⇧⌘S (Windows, Linux Ctrl+Shift+S) workbench.action.files.saveAs
Close ⌘W (Windows Ctrl+F4, Linux Ctrl+W) workbench.action.closeActiveEditor
Close Others ⌥⌘T (Windows, Linux ) workbench.action.closeOtherEditors
Close Group ⌘K W (Windows, Linux Ctrl+K W) workbench.action.closeEditorsInGroup
Close Other Groups workbench.action.closeEditorsInOtherGroups
Close Group to Left workbench.action.closeEditorsToTheLeft
Close Group to Right workbench.action.closeEditorsToTheRight
Close All ⌘K ⌘W (Windows, Linux Ctrl+K Ctrl+W) workbench.action.closeAllEditors
Reopen Closed Editor ⇧⌘T (Windows, Linux Ctrl+Shift+T) workbench.action.reopenClosedEditor
Keep Open ⌘K Enter (Windows, Linux Ctrl+K Enter) workbench.action.keepEditor
Copy Path of Active File ⌘K P (Windows, Linux Ctrl+K P) workbench.action.files.copyPathOfActiveFile
Reveal Active File in Windows ⌘K R (Windows, Linux Ctrl+K R) workbench.action.files.revealActiveFileInWindows
Show Opened File in New Window workbench.action.files.showOpenedFileInNewWindow
Compare Opened File With workbench.files.action.compareFileWith

显示

Command Key Command id
Toggle Full Screen ⌃⌘F (Windows, Linux F11) workbench.action.toggleFullScreen
Toggle Zen Mode ⌘K Z (Windows, Linux Ctrl+K Z) workbench.action.toggleZenMode
Leave Zen Mode Escape Escape workbench.action.exitZenMode
Zoom in ⌘= (Windows, Linux Ctrl+=) workbench.action.zoomIn
Zoom out ⌘- (Windows, Linux Ctrl+-) workbench.action.zoomOut
Reset Zoom ⌘Numpad0 (Windows, Linux Ctrl+Numpad0) workbench.action.zoomReset
Toggle Sidebar Visibility ⌘B (Windows, Linux Ctrl+B) workbench.action.toggleSidebarVisibility
Show Explorer / Toggle Focus ⇧⌘E (Windows, Linux Ctrl+Shift+E) workbench.view.explorer
Show Search ⇧⌘F (Windows, Linux Ctrl+Shift+F) workbench.view.search
Show Source Control ⌃⇧G (Windows, Linux Ctrl+Shift+G) workbench.view.scm
Show Run ⇧⌘D (Windows, Linux Ctrl+Shift+D) workbench.view.debug
Show Extensions ⇧⌘X (Windows, Linux Ctrl+Shift+X) workbench.view.extensions
Show Output ⇧⌘U (Windows Ctrl+Shift+U, Linux Ctrl+K Ctrl+H) workbench.action.output.toggleOutput
Quick Open View ⌃Q (Windows Ctrl+Q, Linux ) workbench.action.quickOpenView
Open New Command Prompt ⇧⌘C (Windows, Linux Ctrl+Shift+C) workbench.action.terminal.openNativeConsole
Toggle Markdown Preview ⇧⌘V (Windows, Linux Ctrl+Shift+V) markdown.showPreview
Open Preview to the Side ⌘K V (Windows, Linux Ctrl+K V) markdown.showPreviewToSide
Toggle Integrated Terminal ⌃` (Windows, Linux Ctrl+`) workbench.action.terminal.toggleTerminal
Command Key Command id
Show Search ⇧⌘F (Windows, Linux Ctrl+Shift+F) workbench.view.search
Replace in Files ⇧⌘H (Windows, Linux Ctrl+Shift+H) workbench.action.replaceInFiles
Toggle Match Case ⌥⌘C (Windows, Linux Alt+C) toggleSearchCaseSensitive
Toggle Match Whole Word ⌥⌘W (Windows, Linux Alt+W) toggleSearchWholeWord
Toggle Use Regular Expression ⌥⌘R (Windows, Linux Alt+R) toggleSearchRegex
Toggle Search Details ⇧⌘J (Windows, Linux Ctrl+Shift+J) workbench.action.search.toggleQueryDetails
Focus Next Search Result F4 search.action.focusNextSearchResult
Focus Previous Search Result ⇧F4 (Windows, Linux Shift+F4) search.action.focusPreviousSearchResult
Show Next Search Term (Windows, Linux Down) history.showNext
Show Previous Search Term (Windows, Linux Up) history.showPrevious

搜索编辑器

Command Key Command id
Open Results In Editor ⌘Enter (Windows, Linux Alt+Enter) search.action.openInEditor
Focus Search Editor Input Escape search.action.focusQueryEditorWidget
Search Again ⇧⌘R (Windows, Linux Ctrl+Shift+R) rerunSearchEditorSearch
Delete File Results ⇧⌘Backspace (Windows, Linux Ctrl+Shift+Backspace) search.searchEditor.action.deleteFileResults

偏好设置

Command Key Command id
Open Settings ⌘, (Windows, Linux Ctrl+,) workbench.action.openSettings
Open Workspace Settings workbench.action.openWorkspaceSettings
Open Keyboard Shortcuts ⌘K ⌘S (Windows, Linux Ctrl+K Ctrl+S) workbench.action.openGlobalKeybindings
Open User Snippets workbench.action.openSnippets
Select Color Theme ⌘K ⌘T (Windows, Linux Ctrl+K Ctrl+T) workbench.action.selectTheme
Configure Display Language workbench.action.configureLocale

调试

Command Key Command id
Toggle Breakpoint F9 editor.debug.action.toggleBreakpoint
Start F5 workbench.action.debug.start
Continue F5 workbench.action.debug.continue
Start (without debugging) ⌃F5 (Windows, Linux Ctrl+F5) workbench.action.debug.run
Pause F6 workbench.action.debug.pause
Step Into F11 workbench.action.debug.stepInto

任务

Command Key Command id
Run Build Task ⇧⌘B (Windows, Linux Ctrl+Shift+B) workbench.action.tasks.build
Run Test Task workbench.action.tasks.test

扩展

Command Key Command id
Install Extension workbench.extensions.action.installExtension
Show Installed Extensions workbench.extensions.action.showInstalledExtensions
Show Outdated Extensions workbench.extensions.action.listOutdatedExtensions
Show Recommended Extensions workbench.extensions.action.showRecommendedExtensions
Show Popular Extensions workbench.extensions.action.showPopularExtensions
Update All Extensions workbench.extensions.action.updateAllExtensions

下一步

既然你已经了解了我们的键绑定支持,接下来...

  • Language Support - 我们的“好、更好、最好”语言网格,看看你可以期待什么
  • Debugging - 这是 VS Code 真正出色的地方
  • Node.js - 使用示例应用程序的端到端Node.js场景

常见问题

如何找出特定键绑定的命令?

键盘快捷键编辑器中,您可以过滤特定的按键组合,以查看哪些命令绑定到哪些键。下面您可以看到Ctrl+Shift+P绑定到显示所有命令,以调出命令面板。

快捷键快速概览

如何为操作添加键绑定,例如,添加Ctrl+D以删除行

默认键盘快捷键中找到一个触发操作的规则,并在你的keybindings.json文件中编写一个修改版本:

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

如何仅为某些文件类型添加快捷键绑定?

在你的when子句中使用editorLangId上下文键:

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

我已经在keybindings.json中修改了我的键绑定;为什么它们不起作用?

最常见的问题是文件中的语法错误。否则,尝试移除when子句或选择不同的key。不幸的是,在这一点上,这是一个试错的过程。