在实际开发中,经常会用到终端进行操作。为了减少外部终端与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
windows是ctrl+c
ctrl+v
linux是shift+ctrl+c
shift+ctrl+v
mac是cmd+c
cmd+v
默认情况下,终端将会在当前目录下打开,我们可以通过terminal.integrated.cwd:"/home/user"
;分割出来的终端,可以通过terminal.integrated.splitCwd:"workSpaceRoot"
PS: CWD current work directory