DEV Community

codemee
codemee

Posted on

自訂 VSCode 延伸套件與設定檔儲存資料夾

VSCode 預設會把相關資料放置在以下位置:

  • 使用者的資料
    • Windows %APPDATA%\Code\User\settings.json
    • macOS $HOME/Library/Application\ Support/Code/User/settings.json
    • Linux $HOME/.config/Code/User/settings.json
  • 延伸套件
    • Windows %USERPROFILE%.vscode\extensions
    • macOS ~/.vscode/extensions
    • Linux ~/.vscode/extensions

要讓 VSCode 將延伸套件與設定檔儲存到特定的資料夾有兩種作法, 使用可攜模式或是命令列參數, 以下分別說明。

可攜模式

要使用可攜模式, 一定要下載 zip 格式的 VSCode, 不能使用安裝版本的 VSCode。解開 zip 後, 只要在解開的資料夾中建立 data 資料夾, 執行 VSCode 就會將延伸套件以及設定檔都存放在 data 資料夾下, 像是這樣:

D:\APPS\PORTABLEAPPS\VSCODE
├───bin
└───data
    ├───extensions
    │   └───cschlosser.doxdocgen-1.4.0
   ...
    └───user-data
        ├───Backups
        ├───blob_storage
        ├───Session Storage
        └───User
Enter fullscreen mode Exit fullscreen mode

命令列參數

VSCode 提供有以兩個參數可以指定儲存的資料夾:

  • --extensions-dir="extension 資料夾"
  • --user-data-dir="設定檔的資料夾"

如果不想每次執行都要下參數, 可以修改 VSCode 的批次檔, Windows 下就是 VSCode 安裝資料夾 bin 下的 code.cmd, 例如改成這樣:

@echo off
setlocal
set VSCODE_DEV=
set ELECTRON_RUN_AS_NODE=1
"%~dp0..\Code.exe" "%~dp0..\resources\app\out\cli.js" --ms-enable-electron-run-as-node --user-data-dir="D:\VSCodeData\settings"  --extensions-dir="D:\VSCodeData\extensions" %*
endlocal
Enter fullscreen mode Exit fullscreen mode

就會把延伸套件儲存到 D:\VSCodeData\extensions 下, 並且把設定檔儲存到 D:\VSCodeData\settings 下了, 像是這樣:

D:\VSCODEDATA
├───extensions
│   └───ms-ceintl.vscode-language-pack-zh-hant-1.66.1
│       └───translations
│           └───extensions
└───settings
    ├───Backups
    ├───blob_storage
    │   └───df921aeb-632f-4640-841d-f1185a88d722
   ...
    ├───Session Storage
    └───User
        ├───globalStorage
        │   └───vscode.json-language-features
        │       └───json-schema-cache
        ├───History
        │   └───-1892a624
        └───workspaceStorage
            └───1648870320
Enter fullscreen mode Exit fullscreen mode

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs