vscode是一款轻量级代码编辑器
可用一段就会很快发现,“轻量级”的vscode并不轻量
不统计不知道,一统计吓一跳,使用了一段时间后,vscode占用了我c盘10g+的空间!
好家伙,于是我决定治理一下vscode,让vscode变得真正的轻量级。
vscode的空间占用分析
vscode所占用的空间,主要包括四大部分(下面是我写此博客时统计的结果):
程序的安装目录
:大约会占用350m%userprofile%\.vscode
:可达800m。主要为:各个拓展。vscode卸载拓展似乎不会删除硬盘上的文件,因此这个里面很大,并且混有很多不用的%userprofile%\appdata\local\microsoft\vscode-cpptools\ipch
:用一段时间能达到4g 与c(++)语言有关,关闭程序后可以直接删。不使用vscode编辑c/c++的用户可能无此痛苦%userprofile%\appdata\roaming\code
:2g+ 存放用户数据、配置等。 (可以通过启动时添加–user-data-dir newdir 来使其他目录作为配置)
可以定期删除的地方,有3. ipch
(可完全删除) 和 4. romaing
(不可完全删除)
4. romaing中,到底哪些可以定期删除
对%userprofile%\appdata\roaming\code
中的文件进行更进一步地分析,我得到了如下结论:
%userprofile%\appdata\roaming\code\cachedextensionvsixs 用一段时间可以达到500m 可以直接删
%userprofile%\appdata\roaming\code\cache 很快几十m
%userprofile%\appdata\roaming\code\cacheddata 很快几十m
%userprofile%\appdata\roaming\code\cachedextensions 安装新插件时,似乎默认不会自动删除,安装插件一多能达到800m
%userprofile%\appdata\roaming\code\cachedextensionvsixs 反正也是与插件有关的,也能达到几百m
%userprofile%\appdata\roaming\code\code cache 十几m
%userprofile%\appdata\roaming\code\crashpad 十几m 用来存放崩溃信息
%userprofile%\appdata\roaming\code\logs 几十m 这个可以直接删,用来存放日志记录
%userprofile%\appdata\roaming\code\service worker 1g
%userprofile%\appdata\roaming\code\service worker\cachestorage 1g 主要位于这里
%userprofile%\appdata\roaming\code\service worker\scriptcache 10m
%userprofile%\appdata\roaming\code\user 600m
%userprofile%\appdata\roaming\code\user\workspacestorage 500m 每打开一个工作目录就会在这个目录下生成一个文件夹
%userprofile%\appdata\roaming\code\user\history 100m
每ctrl+s(仅限有修改的成功的重新保存)一次就会生成一个副本。
这个不是按git的思路只存放更改,而是整个文件全部copy一份。
一个100多k的源码保存十次就是1m,对于习惯随手ctrl+s的用户会占用较大的空间
但是,删除之后将会影响历史版本的还原。
其中,文件名采用了代码混淆技术,每个文件会生成一个文件夹,真正的文件名、各个文件对应文件保存时间都在每个文件夹下的entries.json中
%userprofile%\appdata\roaming\code\user\snippets 这个不能删,并且重装还得记得备份(如果没有自动还原的话)这个是用户自定义的代码片段
能定时删除的目录
%userprofile%\appdata\local\microsoft\vscode-cpptools\ipch
%userprofile%\appdata\roaming\code\cachedextensionvsixs
%userprofile%\appdata\roaming\code\cache
%userprofile%\appdata\roaming\code\cacheddata
%userprofile%\appdata\roaming\code\cachedextensions
%userprofile%\appdata\roaming\code\cachedextensionvsixs
%userprofile%\appdata\roaming\code\code cache
%userprofile%\appdata\roaming\code\crashpad
%userprofile%\appdata\roaming\code\logs
%userprofile%\appdata\roaming\code\service worker\cachestorage
%userprofile%\appdata\roaming\code\service worker\scriptcache
%userprofile%\appdata\roaming\code\user\workspacestorage
%userprofile%\appdata\roaming\code\user\history
这么多文件夹总不可能手动地一个一个地删除,因此我写了一个脚本:
@rem example:
@rem del "%userprofile%/appdata/local/microsoft/vscode-cpptools/ipch/" /s /q /f
@rem rd "%userprofile%/appdata/local/microsoft/vscode-cpptools/ipch/" /s /q
@rem md "%userprofile%/appdata/local/microsoft/vscode-cpptools/ipch/"
@echo off
call:emptyonedir "%userprofile%\appdata\local\microsoft\vscode-cpptools\ipch"
call:emptyonedir "%userprofile%\appdata\roaming\code\cachedextensionvsixs"
call:emptyonedir "%userprofile%\appdata\roaming\code\cache"
call:emptyonedir "%userprofile%\appdata\roaming\code\cacheddata"
call:emptyonedir "%userprofile%\appdata\roaming\code\cachedextensions"
call:emptyonedir "%userprofile%\appdata\roaming\code\cachedextensionvsixs"
call:emptyonedir "%userprofile%\appdata\roaming\code\code cache"
call:emptyonedir "%userprofile%\appdata\roaming\code\crashpad"
call:emptyonedir "%userprofile%\appdata\roaming\code\logs"
call:emptyonedir "%userprofile%\appdata\roaming\code\service worker\cachestorage"
call:emptyonedir "%userprofile%\appdata\roaming\code\service worker\scriptcache"
call:emptyonedir "%userprofile%\appdata\roaming\code\user\workspacestorage"
call:emptyonedir "%userprofile%\appdata\roaming\code\user\history"
goto end
:emptyonedir rem same as let empty [path] /q
echo empty %1
echo del %1 /s /q /f
del %1 /s /q /f
echo rd %1 /s /q
rd %1 /s /q
echo md %1
md %1
:end
只需要将这个脚本另存为cleanvscode.bat,并定期双击运行一次,就能定期释放大量空间
当然,释放的空间直接取决于你的vscode所产生的缓存大小,间接取决于你的vscode的使用次数。
最好关闭vscode后再运行脚本。
⚠️warning
运行脚本后再次运行vscode基本上看不出什么不同,只是当前工作路径下所打开的文件需要重新手动点击打开。
毕竟是一个能删除很多东西的脚本,因此请谨慎使用。
我作为本篇博客的原创博主,只是为大家提供了一个便捷的方法,但是其可能造成的后果,博主并不承担责任。
但是大家可以放心的是,我自己也在定期运行这个脚本。
准备有空的时候将其加入windows计划,以实现定期地自动释放空间。
视频版演示:
轻量级的vscode为何越用越大?为什么吃了我c盘10g?如何无痛清理vscode缓存?手把手教你为c盘瘦身
发表评论