且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

更改 Visual Studio Code 集成终端的默认路径

更新时间:2022-12-04 18:22:55

简短回答

编辑用户首选项 "terminal.integrated.cwd": "" 到您希望集成终端打开的路径.

Short answer

Edit the user preference "terminal.integrated.cwd": "" to the path that you want the integrated terminal to open to.


相同的答案,但详细的分步版本,

The same answer, but the long step-by-step version,

在 Visual Studio Code 中转到:

In Visual Studio Code go to:

菜单文件首选项设置

Menu FilePreferencesSettings


现在您已进入用户设置",使用窗口顶部的搜索设置"栏粘贴或输入:


Now that you are in the "User Settings", using the "Search Settings" bar across the top of the window paste or type this:

terminal.integrated.cwd

terminal.integrated.cwd


结果将列出以下内容:


It will list the following as a result:

// 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": "",


您会注意到它不会让您在此处键入以更改此设置.那是因为您无法更改默认设置.您需要更改您的个人设置.方法如下...


点击此选项左侧的铅笔图标,然后点击弹出的复制到设置"选项.


Click the pencil icon to the left of the this option and then the "Copy to Settings" option that pops-up.


您应该有一个分屏,其中屏幕右侧有标题将您的设置放在此处以覆盖默认设置. 这是您进行更改的正确位置.您可能已经在此处列出了一些个性化设置.


You should have a split screen in which the right side of the screen has the heading Place your settings here to overwrite the Default Settings. This is the correct place for you to make changes. You might already have a few personalized settings listed here.


当您单击复制到设置"时,它会自动为您添加此行:


When you clicked "Copy to Settings" it automatically added this line for you:

"terminal.integrated.cwd": ""

"terminal.integrated.cwd": ""

请注意,此列表中的最后一项将不会有尾随逗号,但列表中它之前的任何项目都需要一个.

Notice that whichever item is last in this list will not have a trailing comma but any items before it in the list will require one.

仅供参考:您可以自己简单地将其输入或复制/粘贴到个性化设置中,但遵循这些步骤是学习根据需要更改其他首选项的过程.


现在您可以键入以设置要使用的路径.确保使用 \\ 代替 \ 并且不需要尾随 \.例如,包含这一行将始终在 baz 目录中启动您的终端:


Now you are able to type to set the path you want to use. Make sure to use \\ in place of \ and you do not need the trailing \. For example including this line would always start your terminal in the baz directory:

{
    "terminal.integrated.cwd": "C:\\Users\\foo\\bar\\baz"
}


要应用更改,只需保存重新启动 Visual Studio Code.