VS Code 高级使用技巧整理
之前已经写了一片VS Code 的基础技巧,里面包含了经常使用的文件跳转,插件等基本的技巧,如果有问题的话,可以查看这个链接进行查看。
在这里讲的是一些高级的编辑技巧,如果学会了,并在平时的工作中使用,会提高至少50%以上的效率。
编辑技巧
接下来会有几个针对于编写代码时的编辑技巧,如果你的快捷键不是特别舒服,你可以查看上一篇基础,里面可以修改成之前常用编辑器的快捷键。
多光标选择
Mac: opt+cmd+up or opt+cmd+down
Windows: ctrl+alt+up or ctrl+alt+down
Linux: alt+shift+up or alt+shift+down
![multi cursor selection1](http://w.o.perfowl.com/2018-09-12-multi%20cursor.gif)
![multi cursor selection 2](http://w.o.perfowl.com/2018-09-12-multi%20cursor%20second%20example.gif)
同时选择多个当前选中的标签
![add more cursors to current selection](http://w.o.perfowl.com/2018-09-12-add%20cursor%20to%20all%20occurrences%20of%20current%20selection.gif)
排列成一行
Mac: ctrl+j
Windows/Linux:这两个系统没有默认设置的快捷键,可以去 editor.action.joinLines
配置自己喜欢的快捷键
![join line](http://w.o.perfowl.com/2018-09-12-Join%20lines.gif)
复制到上/下行
什么意思呢?就是将你复制的内容直接沾到上/下行。话不多说,看示例就懂了。
Mac: opt+shift+up or opt+shift+down
Windows / Linux: shift+alt+down or shift+alt+up
![copy line up/down](http://w.o.perfowl.com/2018-09-12-copy%20line%20down.gif)
代码块选择
Mac: ctrl+shift+cmd+left or ctrl+shift+cmd+right
Windows / Linux: shift+alt+left or shift+alt+right
![shrink/expand selection](http://w.o.perfowl.com/2018-09-12-shrink%20expand%20selection.gif)
文件内快速定位
Mac: cmd+shift+o
Windows / Linux: ctrl+shift+o
![go to symbol in file](http://w.o.perfowl.com/2018-09-12-Find%20by%20symbol.gif)
同样也可以直接在vs code的文件跳转窗口(cmd+p
)输入@:
操作。
![adding a colon](http://w.o.perfowl.com/2018-09-12-group%20symbols%20by%20kind.png)
在项目内快速定位
Mac: cmd+t
Windows / Linux: ctrl+t
![go to symbol in workspace](http://w.o.perfowl.com/2018-09-12-go%20to%20symbol%20in%20workspace.png)
跳转到指定行
Mac: ctrl+g or cmd+p, :
Windows / Linux: ctrl+g
![navigate to a specific line](http://w.o.perfowl.com/2018-09-12-navigate%20to%20line.gif)
返回光标位置
Mac: cmd+u
Windows / Linux: ctrl+u
![undo cursor position](http://w.o.perfowl.com/2018-09-12-undo%20cursor%20position.gif)
将本行内容上/下移动
Mac: opt+up or opt+down
Windows / Linux: alt+up or alt+down
![move line up and down](http://w.o.perfowl.com/2018-09-12-move%20line%20up%20and%20down.gif)
移除两端多余的空格
Mac: cmd+k cmd+x
Windows / Linux: ctrl+k ctrl+x
![trim trailing whitespace](http://w.o.perfowl.com/2018-09-12-trailing%20whitespace.gif)
代码格式化
当前选中代码
Mac: cmd+k, cmd+f
Windows / Linux: ctrl+k, ctrl+f
整个文件格式化
Windows / Linux: shift+alt+f
![whole document format](http://w.o.perfowl.com/2018-09-12-code%20formatting.gif)
代码折叠
Mac: alt+cmd+[ and alt+cmd+]
Windows / Linux: ctrl+shift+[ and ctrl+shift+]
![code folding](http://w.o.perfowl.com/2018-09-12-code%20folding.gif)
选择当前行
Mac: cmd+i
Windows / Linux: ctrl+i
![select current line](http://w.o.perfowl.com/2018-09-12-select%20current%20line.gif)
跳转到文件顶部/尾部
Mac: cmd+up and cmd+down
Windows: ctrl+up and ctrl+down
Linux: ctrl+home and ctrl+end
![navigate to beginning and end of file](http://w.o.perfowl.com/2018-09-12-navigate%20to%20beginning%20and%20end%20of%20file.gif)
打开 Markdown 预览
在 Markdown 文件中。
Mac: shift+cmd+v
Windows / Linux: ctrl+shift+v
![open markdown preview](http://w.o.perfowl.com/2018-09-12-toggle%20readme%20preview.gif)
Markdown 编辑 + 预览
在 Markdown 文件中。
Mac: cmd+k v
Windows / Linux: ctrl+k v
![side by side markdown edit and preview](http://w.o.perfowl.com/2018-09-12-markdown%20sync.gif)
智能感知
这个功能是 VS Code里面的主要特色之一,有多种表现形式,除了提供代码自动补全,显示部分该方法的缩略信息,还能直接查看原方法。
你可以在任何时候,尝试使用ctrl+space
来激活这个功能,他会根据你当前的位置进行提醒。
![IntenlliSense](http://w.o.perfowl.com/2018-09-12-intellisense.gif)
Peek
选择代码,然后键盘输入alt+f12
。也可以直接用鼠标右键直接查看peek。这个查看是不会跳转,直接在显示器出现一个弹窗查看。
![peek](http://w.o.perfowl.com/2018-09-12-peek.gif)
查看原码
选择代码,键盘输入f12
。也可以直接用鼠标右键选择go definition
,也可以直接 cmd+点击
的方法进行查看。跳转过后,可以直接按alt+left
( Mac:ctrl+-
)进行直接返回。
![Go to Definition](http://w.o.perfowl.com/2018-09-12-go%20to%20definition.gif)
查看所有的引用
选择代码,键盘输入shift+f12
,也可以直接使用右键菜单 find all references
。查看所有引用的位置,点击后直接跳转。
![find all references](http://w.o.perfowl.com/2018-09-12-go%20to%20definition.gif)
重命名
选择代码,键盘输入f2
,也可以直接使用右键rename symbol
![rename symbol](http://w.o.perfowl.com/2018-09-12-rename%20symbol.gif)
代码块
创建自定义代码块
File > Preferences > User Snippets,选择语言,然后创建代码块。
"create component": {
"prefix": "component",
"body": [
"class $1 extends React.Component {",
"",
" render() {",
" return ($2);",
" }",
"",
"}"
]
},
这些技巧刚开始在使用的时候可能会比较慢,但是稍微熟悉了之后,写代码的速度将会大幅度提升,基本能做到双手置放在键盘,不用碰鼠标的大神境界了。
微信公众号:产品看世界 chanpinkanshijie
![产品看世界二维码](http://w.o.perfowl.com/qrcode_for_gh_e4e19aa4bfa5_258.jpg)