Visual Studio Code的常用快捷键

一、Visual Studio Code简介

  Visual Studio Code是个牛逼的编辑器,启动非常快,完全可以用来代替其他文本文件编辑工具。又可以用来做开发,支持各种语言,相比其他IDE,轻量级完全可配置还集成Git感觉非常的适合前端开发。 所以我仔细研究了一下文档未来可能会作为主力工具使用。

  一、主命令框

  Visual Studio Code最重要的功能就是 F1Ctrl+Shift+P打开的命令面板了,在这个命令框里可以执行VSCode的任何一条命令,甚至关闭这个编辑器。
  按一下Backspace会进入到Ctrl+P模式里
  在Ctrl+P下输入>又可以回到Ctrl+Shift+P模式。
  在Ctrl+P窗口下还可以

  1. 直接输入文件名,跳转到文件
  2. ? 列出当前可执行的动作
  3. ! 显示Errors或Warnings,也可以`Ctrl+Shift+M
  4. : 跳转到行数,也可以Ctrl+G直接进入
  5. @ 跳转到symbol(搜索变量或者函数),也可以Ctrl+Shift+O直接进入
  6. @:根据分类跳转symbol,查找属性或函数,也可以Ctrl+Shift+O后输入:进入
  7. # 根据名字查找symbol,也可以Ctrl+T

二、Visual Studio Code常用快捷键

  官方快捷键大全:https://code.visualstudio.com/docs/customization/keybindings

  一、编辑器与窗口管理

  1、同时打开多个窗口(查看多个项目)

  1. 打开一个新窗口: Ctrl+Shift+N
  2. 关闭窗口: Ctrl+Shift+W

  2、同时打开多个编辑器(查看多个文件)

  1. 新建文件 Ctrl+N
  2. 文件之间切换 Ctrl+Tab
  3. 切出一个新的编辑器(最多3个)Ctrl+,也可以按住Ctrl鼠标点击Explorer里的文件名
  4. 左中右3个编辑器的快捷键Ctrl+1Ctrl+2Ctrl+3
  5. 3个编辑器之间循环切换 Ctrl+`
  6. 编辑器换位置,Ctrl+k然后按LeftRight

  二、代码编辑

  1、格式调整

  1. 代码行缩进Ctrl+[ Ctrl+]
  2. Ctrl+CCtrl+V如果不选中,默认复制或剪切一整行
  3. 代码格式化:Shift+Alt+F,或Ctrl+Shift+P后输入format code
  4. 上下移动一行: Alt+Up 或 Alt+Down
  5. 向上向下复制一行: Shift+Alt+UpShift+Alt+Down
  6. 在当前行下边插入一行Ctrl+Enter
  7. 在当前行上方插入一行Ctrl+Shift+Enter

  2、光标相关

  1. 移动到行首:Home
  2. 移动到行尾:End
  3. 移动到文件结尾:Ctrl+End
  4. 移动到文件开头:Ctrl+Home
  5. 移动到定义处:F12
  6. 定义处缩略图:只看一眼而不跳转过去Alt+F12
  7. 移动到后半个括号 Ctrl+Shift+]
  8. 选择从光标到行尾Shift+End
  9. 选择从行首到光标处Shift+Home
  10. 删除光标右侧的所有字Ctrl+Delete
  11. Shrink/expand selection: Shift+Alt+LeftShift+Alt+Right
  12. Multi-Cursor:可以连续选择多处,然后一起修改,Alt+Click添加cursor或者Ctrl+Alt+Down 或 Ctrl+Alt+Up
  13. 同时选中所有匹配的Ctrl+Shift+L
  14. Ctrl+D下一个匹配的也被选中(被我自定义成删除当前行了,见下边Ctrl+Shift+K)
  15. 回退上一个光标操作Ctrl+U

  3、重构代码

  1. 找到所有的引用:Shift+F12
  2. 同时修改本文件中所有匹配的:Ctrl+F12
  3. 重命名:比如要修改一个方法名,可以选中后按F2,输入新的名字,回车,会发现所有的文件都修改过了。
  4. 跳转到下一个Error或Warning:当有多个错误时可以按F8逐个跳转
  5. 查看diff 在explorer里选择文件右键 Set file to compare,然后需要对比的文件上右键选择Compare with 'file_name_you_chose'.

  4、查找替换

  1. 查找 Ctrl+F
  2. 查找替换 Ctrl+H
  3. 整个文件夹中查找 Ctrl+Shift+F
  4. 匹配符:
  5. * to match one or more characters in a path segment
  6. ? to match on one character in a path segment
  7. ** to match any number of path segments ,including none
  8. {} to group conditions (e.g. {**/*.html,**/*.txt} matches all html and txt files)
  9. [] to declare a range of characters to match (e.g., example.[0-9] to match on example.0,example.1, …

  5、显示相关

  1. 全屏:F11
  2. zoomIn/zoomOut:Ctrl + =/Ctrl + -
  3. 侧边栏显/隐:Ctrl+B
  4. 侧边栏4大功能显示:
1 Show Explorer     Ctrl+Shift+E
2 Show Search       Ctrl+Shift+F
3 Show Git          Ctrl+Shift+G
4 Show Debug        Ctrl+Shift+D

  5.Show Output Ctrl+Shift+U

  6、其他

  • 自动保存:File -> AutoSave ,或者Ctrl+Shift+P,输入 auto

  三、修改默认的快捷键

  File -> Preferences -> Keyboard Shortcuts

  修改keybindings.json,我的显示在这里C:UsersAdministratorAppDataRoamingCodeUserkeybindings.json

 1 // Place your key bindings in this file to overwrite the defaults
 2 [
 3     //ctrl+space被切换输入法快捷键占用
 4     {
 5         "key": "ctrl+alt+space",
 6         "command": "editor.action.triggerSuggest",
 7         "when": "editorTextFocus"
 8     },
 9     // ctrl+d删除一行
10     {
11         "key": "ctrl+d",
12         "command": "editor.action.deleteLines",
13         "when": "editorTextFocus"
14     },
15     {
16         "key": "ctrl+shift+k", //与删除一行的快捷键互换了:)
17         "command": "editor.action.addSelectionToNextFindMatch",
18         "when": "editorFocus"
19     },
20     //ctrl+shift+/多行注释
21     {
22         "key":"ctrl+shift+/",
23         "command": "editor.action.blockComment",
24         "when": "editorTextFocus"
25     }
26 ]
原文地址:https://www.cnblogs.com/happy-king/p/8902595.html