在实际开发中,经常会用到终端进行操作。为了减少外部终端与VSCODE之间的频繁切换,VSCODE内置了集成终端界面方便我们操作。
如何打开?
最简单的方式就是:ctrl+ ‘
` ‘。打开后的界面如下:下拉框可以管理已存在终端、默认终端、终端的设置。VS可以创建多个终端ctrl+shift+ ‘
` ‘,你也可以在通过下拉栏中开启split成左右两个终端ctrl+shift+5。
配置终端
VSCODE有默认终端:
- Linux/macOS:$SHELL
- Windows10:PowerShell
- 早期Windows:cmd.exe
一般在下拉栏可以找到现在可以使用的终端,如果没有,那么我们就要通过JSON进行设置了:termial.integrated.shell.windows:"C:\\Windows\\system32\\cmd.exe"
在终端加载时,我们还可以传递参数,如Linux还需要运行.bash_profile,那么可以这么写:terminal/integrated.shellArgs.linux:["-l"],除此,集成终端的shell shellArgs env cwd还支持变量设置。下面例子使用了当前文件目录作为集成终端的工作目录:
"termial.integrated.cwd":"${fileDirName}"
这个fileDirName是内置的变量,你可以在https://code.visualstudio.com/docs/editor/variables-reference找到相关说明,它主要是帮助我们描述路径、文件名等字符串和子串。
终端还有很多属性可以设置:
- terminal.integrated.fontFamily字体
- terminal.integrated.fontSize字体大小
- terminal.integrated.fontWeight字体粗细
- terminal.integrated.fontWeightBold加粗
- terminal.integrated.lineWeight
终端其他功能
终端浏览
| 快捷键 | 功能 |
|---|---|
| ctrl+` | 显示终端 |
| ctrl+shift+1 | 创建一个新终端 |
| ctrl+alt+pageup | 向上翻动 |
| ctrl+alt+pagedown | 向下翻动 |
| shift+pageup | 向上滚动一页 |
| shift+pagedown | 向下滚动一页 |
| ctrl+home | 滚到顶部 |
| ctrl+end | 滚到底部 |
终端复制粘贴
windows是ctrl+cctrl+v
linux是shift+ctrl+cshift+ctrl+v
mac是cmd+ccmd+v
设置终端打开路径
默认情况下,终端将会在当前目录下打开,我们可以通过terminal.integrated.cwd:"/home/user";分割出来的终端,可以通过terminal.integrated.splitCwd:"workSpaceRoot"
PS: CWD current work directory
