如何更改全局 .vscode 文件夹的位置? [英] How to change the location of the global .vscode folder?

查看:173
本文介绍了如何更改全局 .vscode 文件夹的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Linux 上设置 Visual Studio Code.

由于机器是共享的,我的$HOME文件夹大小受限,没有给我留下扩展空间(存储在$HOME/.vscode/),这使我无法安装它们.

我在其他开发目录上确实有足够的空间,但是我找不到一种方法来告诉 Visual Studio Code 为全局 使用另一个路径,而不是 $HOME.vscode 文件夹.

有没有办法在不改变我的 $HOME 的情况下做到这一点?

编辑
虽然评论中的建议解决了将扩展安装在不同文件夹中的问题 - 在我的 $HOME 文件夹中有一个巨大的 .cache 文件夹由 vscode 填充...
有没有办法以某种方式改变到这个路径?

解决方案

一些选项按推荐顺序:

为扩展和用户数据使用自定义目录

您最好的选择可能是告诉 VS Code 为扩展和用户数据使用自定义路径.这是可行的,因为它会占用磁盘空间的扩展和缓存文件夹,因为缓存文件夹位于用户数据文件夹下.

您在调用 VS Code 时提供自定义路径作为命令行参数.使用 /mnt/extdir/vsc-ext//mnt/extdir/vsc-user-data/ 作为所需外部目录的示例,您可以使用:>

$ code --extensions-dir/mnt/extdir/vsc-ext/--user-data-dir/mnt/extdir/vsc-user-data/.

你可以在你的 shell 启动脚本中添加一个别名来促进这个:

alias code='code --extensions-dir/mnt/extdir/vsc-ext/--user-data-dir/mnt/extdir/vsc-user-data/'

然后您可以继续使用,例如code . 像往常一样,但让 VS Code 使用外部目录进行扩展和缓存.

来自 CLI 文档:<块引用>

--extensions-dir

设置扩展的根路径.在便携模式下无效.

--user-data-dir

指定保存用户数据的目录,以 root 身份运行时很有用.在便携模式下无效.


顺便提一下:我运行以下命令以确认缓存文件夹实际上位于用户数据目录下:

$ mkdir vs-user-data &&代码 --user-data-dir vs-user-data .&&睡眠 3 &&ls vs-user-data |grep -i 缓存缓存数据代码缓存GPU缓存

使用便携模式

使用便携模式 (文档),全部用户数据存储在您选择的安装目录中.

这在您的情况下可能会正常工作,但缺点是安装和让更新 VS Code 变得更麻烦.

使用符号链接

这可能也有效,但会是一个劣质的选择.上面给出的其他解决方案得到官方支持并且更加强大.

I am setting up Visual Studio Code on Linux.

Since the machine is shared, my $HOME folder is restricted in size, leaving me no space for extensions (which are stored in $HOME/.vscode/), and that fails my attempts to install them.

I do have enough space on other development directory, but I couldn't find a way to tell Visual Studio Code to use another path, rather than $HOME, for the global .vscode folder.

Is there a way to do that without changing my $HOME?

EDIT
While the suggestion in the comment solved the issue of extensions being installed in a different folder - there's a HUGE .cache folder that's being filled by vscode in my $HOME folder...
Is there a way to somehow change to path to this one as well?

解决方案

Some options in order of recommendation:

Use custom directories for extensions and user data

Your best option is probably to tell VS Code to use custom paths for extensions and user data. This would work since it would be the extensions and cache folders that take up disk space, and since the cache folders are located under the user data folder.

You provide the custom paths as command line arguments when invoking VS Code. Using /mnt/extdir/vsc-ext/ and /mnt/extdir/vsc-user-data/ as examples for desired external directories, you'd use:

$ code --extensions-dir /mnt/extdir/vsc-ext/ --user-data-dir /mnt/extdir/vsc-user-data/ .

You can add an alias to your shell startup script to facilitate this:

alias code='code --extensions-dir /mnt/extdir/vsc-ext/ --user-data-dir /mnt/extdir/vsc-user-data/'

Then you can continue to use just e.g. code . as usual, but have VS Code use the external directories for extensions and cache.

From the CLI documentation:

--extensions-dir <dir>

Set the root path for extensions. Has no effect in Portable Mode.

--user-data-dir <dir>

Specifies the directory that user data is kept in, useful when running as root. Has no effect in Portable Mode.


Just a side note: I ran the following to confirm that the cache folders are actually under the user data directory:

$ mkdir vs-user-data && code --user-data-dir vs-user-data . && sleep 3 && ls vs-user-data | grep -i cache
CachedData
Code Cache
GPUCache

Use portable mode

Using portable mode (documentation), all user data is stored in the installation directory, which is chosen by you.

This would probably work fine in your case, but a drawback would be a non-standard way for installation and making updating VS Code more cumbersome.

Use symlinks

That would probably work as well, but would be an inferior option. The other solutions given above are officially supported and more robust.

这篇关于如何更改全局 .vscode 文件夹的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆