VSCode使用技巧

VSCode本身是一款非常好用的轻量级编辑器,初识这一编辑器是在智行者的冯大佬指导下进行的,后面自己也逐渐喜欢上了这款IDE;突然很怀念智行者的小伙伴们!
比较详细全面的介绍可以参考博文:非常全的VSCode快捷键

代码比较

在vscode主界面左侧选取待比较文件1,右键点击 select for compare;点击待比较文件2,右键点击 compare with selected。
此时在VScode主界面会出现两个文件的比较文件,很详细。

主命令框 Command Palette

最重要的功能就是 F1 或 Ctrl+Shift+P 打开的命令面板了,在这个命令框里可以执行VSCode的任何一条命令,可以查看每条命令对应的快捷键,甚至可以关闭这个编辑器。
比如常见的关于indent 的转换,主要包括space 与 tab的转换,因为目前在linux下不太了解vim/gedit如何很好的做相关转换。

Ctrl+P

Ctrl+Shift+P环境下敲 Backspace可以进入到Ctrl+P模式;在Ctrl+P模式下输入 > 则又回到 Ctrl+Shift+P的模式。

在Ctrl+P窗口下可以直接输入文件名,快速打开文件
? 列出当前可执行的动作
! 显示Errors或Warnings,也可以Ctrl+Shift+M
: 跳转到行数,也可以Ctrl+G直接进入
@ 跳转到symbol(搜索变量或者函数),也可以Ctrl+Shift+O直接进入
@:根据分类跳转symbol,查找属性或函数,也可以Ctrl+Shift+O后输入:进入
# 根据名字查找symbol,也可以Ctrl+T

常用快捷键

编辑器与窗口管理

同时打开多个窗口(查看多个项目)
打开一个新窗口: Ctrl+Shift+N
关闭窗口: Ctrl+Shift+W

同时打开多个编辑器(查看多个文件)
新建文件 Ctrl+N
历史打开文件之间切换 Ctrl+Tab,Alt+Left,Alt+Right
切出一个新的编辑器(最多3个)Ctrl+\,也可以按住Ctrl鼠标点击Explorer里的文件名
左中右3个编辑器的快捷键Ctrl+1 Ctrl+2 Ctrl+3
3个编辑器之间循环切换 Ctrl+`
编辑器换位置,Ctrl+k然后按Left或Right

代码编辑

格式调整
代码行缩进Ctrl+[, Ctrl+]
折叠打开代码块 Ctrl+Shift+[, Ctrl+Shift+]
Ctrl+C Ctrl+V如果不选中,默认复制或剪切一整行
代码格式化:Shift+Alt+F,或Ctrl+Shift+P后输入format code

修剪空格Ctrl+Shift+X
上下移动一行: Alt+Up 或 Alt+Down
向上向下复制一行: Shift+Alt+Up或Shift+Alt+Down
在当前行下边插入一行Ctrl+Enter
在当前行上方插入一行Ctrl+Shift+Enter

光标相关
移动到行首:Home
移动到行尾:End
移动到文件结尾:Ctrl+End
移动到文件开头:Ctrl+Home
移动到后半个括号 Ctrl+Shift+]
选中当前行Ctrl+i
选择从光标到行尾Shift+End
选择从行首到光标处Shift+Home
删除光标右侧的所有字Ctrl+Delete
Shrink/expand selection: Shift+Alt+Left和Shift+Alt+Right
Multi-Cursor:可以连续选择多处,然后一起修改,Alt+Click添加cursor或者Ctrl+Alt+Down 或 Ctrl+Alt+Up
同时选中所有匹配的Ctrl+Shift+L
Ctrl+D下一个匹配的也被选中(被我自定义成删除当前行了,见下边Ctrl+Shift+K)
回退上一个光标操作Ctrl+U

重构代码
跳转到定义处:F12 之后可以按 alt+左箭头返回,alt+右箭头重复跳转
多单词匹配:Ctrl+d
删除整个单词:Ctrl+backspace
向上或向下移动整行:alt+上/下箭头
删除一整行:Ctrl+x
Shift+Alt + ↓ / ↑:向上/向下复制行 Copy line up/down
Ctrl+Enter:在下面插入行 Insert line below
Ctrl+Shift+Enter:在上面插入行 Insert line above

定义处缩略图:只看一眼而不跳转过去Alt+F12
列出所有的引用:Shift+F12
同时修改本文件中所有匹配的:Ctrl+F12
重命名:比如要修改一个方法名,可以选中后按F2,输入新的名字,回车,会发现所有的文件都修改过了。
跳转到下一个Error或Warning:当有多个错误时可以按F8逐个跳转
查看diff 在explorer里选择文件右键 Set file to compare,然后需要对比的文件上右键选择Compare with ‘file_name_you_chose’.

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

显示相关
全屏:F11
zoomIn/zoomOut:Ctrl + =/Ctrl + -
侧边栏显/隐:Ctrl+B
侧边栏4大功能显示:
Show Explorer Ctrl+Shift+E
Show SearchCtrl+Shift+F
Show GitCtrl+Shift+G
Show DebugCtrl+Shift+D
Show OutputCtrl+Shift+U
预览markdownCtrl+Shift+V

自定义settings.json

User settings 是全局设置,任何vs Code打开的项目都会依此配置。默认存储在:

Windows: %APPDATA%\Code\User\settings.json
Mac: $HOME/Library/Application Support/Code/User/settings.json
Linux: $HOME/.config/Code/User/settings.json

Workspace settings 是本工作区的设置,会覆盖上边的配置,存储在工作区的.vocode文件夹下。

几乎所有设定都在settings.json里,包括

Editor Configuration - font, word wrapping, tab size, line numbers, indentation, …
Window Configuration - restore folders, zoom level, …
Files Configuration - excluded file filters, default encoding, trim trailing whitespace, …
File Explorer Configuration - encoding, WORKING FILES behavior, …
HTTP Configuration - proxy settings
Search Configuration - file exclude filters
Git Configuration - disable Git integration, auto fetch behavior
Telemetry Configuration - disable telemetry reporting, crash reporting
HTML Configuration - HTML format configuration
CSS Configuration - CSS linting configuration
JavaScript Configuration - Language specific settings
JSON Configuration - Schemas associated with certain JSON files
Markdown Preview Configuration - Add a custom CSS to the Markdown preview
Less Configuration - Control linting for Less
Sass Configuration - Control linting for Sass
TypeScript Configuration - Language specific settings
PHP Configuration - PHP linter configuration

例如可以修改让vscode认识.glsl扩展名

{

    // Configure file associations to languages (e.g. "*.extension": "html"). These have precedence over the default associations of the languages installed.
    "files.associations": {
        "*.glsl": "shaderlab"
    }
}
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值