简答
将用户首选项"terminal.integrated.cwd": "" 编辑为您希望集成终端打开的路径。
长答案
相同的答案,但步骤较长,
在 Visual Studio Code 中转到:
菜单文件 → 首选项 → 设置
现在您位于“用户设置”中,使用窗口顶部的“搜索设置”栏粘贴或输入以下内容:
terminal.integrated.cwd
结果将列出以下内容:
// An explicit start path where the terminal will be launched, this is used
as the current working directory (cwd) for the shell process. This may be
particularly useful in workspace settings if the root directory is not a
convenient cwd.
"terminal.integrated.cwd": "",
您会注意到它不允许您在此处键入以更改此设置。那是因为您无法更改默认设置。相反,您需要更改您的个人设置。方法如下...
点击此选项左侧的铅笔图标,然后点击弹出的“复制到设置”选项。
您应该有一个分屏,其中屏幕右侧的标题为Place your settings here to overwrite the Default Settings. 这是您进行更改的正确位置。您可能已经在此处列出了一些个性化设置。
当您单击“复制到设置”时,它会自动为您添加这一行:
"terminal.integrated.cwd": ""
请注意,此列表中最后一个项目不会有尾随逗号,但列表中它之前的任何项目都需要一个逗号。
仅供参考:您可以自己简单地输入或复制/粘贴到个性化设置中,但遵循这些步骤是学习根据需要更改其他偏好的过程。
现在您可以键入以设置要使用的路径。确保使用\\ 代替\,并且您不需要尾随\。例如,包含此行将始终在 baz 目录中启动您的终端:
{
"terminal.integrated.cwd": "C:\\Users\\foo\\bar\\baz"
}
要应用更改,只需保存并重新启动 Visual Studio Code。