如何将VSCode及插件、配置文件(不含临时文件)整合并迁移至OneDrive或USB磁盘?
Alright, let's walk through how to fully migrate your VS Code setup—custom settings, installed plugins, everything—to a single folder on OneDrive or a USB drive, while skipping those unnecessary temporary files that don't need to come along. Here's a straightforward, step-by-step breakdown:
Step 1: Shut Down VS Code Completely
First things first, close VS Code entirely. Check your task manager (Windows) or activity monitor (Mac/Linux) to make sure no Code.exe or Code processes are running in the background—if they are, end them. This prevents file locks that might mess up the copy process.
Step 2: Locate VS Code's Core Data Folders
VS Code stores its data in a few different places depending on your OS. Here's where to find them:
Windows
- Settings & Config:
%APPDATA%\Code(this includes your settings.json, keybindings, workspace data, etc.) - Installed Plugins:
%USERPROFILE%\.vscode\extensions - Temp/Cache Files:
%TEMP%\Codeor%LOCALAPPDATA%\Temp\Code— we're ignoring these
Mac
- Settings & Config:
~/Library/Application Support/Code - Installed Plugins:
~/.vscode/extensions - Temp/Cache Files:
~/Library/Caches/Code— skip this folder
Linux
- Settings & Config:
~/.config/Code - Installed Plugins:
~/.vscode/extensions - Temp/Cache Files:
~/.cache/Code— no need to copy this
Step 3: Create a Unified Folder on Your Target Location
Head to your OneDrive or USB drive and create a single folder to hold all your VS Code data—let's call it VSCode-Portable for clarity. Inside this folder, make two subfolders:
data(will hold your settings/config)extensions(will hold your plugins)
Step 4: Copy the Necessary Files
Now move the important folders into your new portable setup:
- Copy the entire
Codeconfig folder (from Step 2) into thedatasubfolder you just created. - Copy the entire
extensionsfolder (from Step 2) into theextensionssubfolder.
Critical Note: Do NOT copy any temp/cache folders—these are automatically generated when VS Code runs, and bringing them along can cause conflicts or unnecessary bloat.
Step 5: Configure VS Code to Use the Portable Folders
To make VS Code load your portable data instead of the default locations, you'll need to create a startup script (batch file for Windows, shell script for Mac/Linux) in your VSCode-Portable folder.
Windows (Batch File)
Create a new text file named VSCode-Portable.bat, paste this code, and update the path to your VS Code Code.exe:
@echo off start "" "C:\Program Files\Microsoft VS Code\Code.exe" --user-data-dir "%~dp0data" --extensions-dir "%~dp0extensions"
(If you're using a portable version of VS Code already, point to the Code.exe in that folder instead.)
Mac (Shell Script)
Create a new text file named VSCode-Portable.sh, paste this code, and update the app path if needed:
#!/bin/bash open -a "/Applications/Visual Studio Code.app" --args --user-data-dir "$(dirname "$0")/data" --extensions-dir "$(dirname "$0")/extensions"
Then open Terminal, navigate to your VSCode-Portable folder, and run chmod +x VSCode-Portable.sh to make the script executable.
Linux (Shell Script)
Create a new text file named VSCode-Portable.sh, paste this code:
#!/bin/bash code --user-data-dir "$(dirname "$0")/data" --extensions-dir "$(dirname "$0")/extensions"
Make it executable with chmod +x VSCode-Portable.sh.
Step 6: Test Your Portable Setup
Double-click the startup script you created to launch VS Code. Check that all your plugins are installed, your settings are intact, and everything works as expected. Once you're sure it's working, you can back up the original default folders (from Step 2) or delete them if you don't need them anymore.
Extra Tips for OneDrive Users
- Wait for OneDrive to finish syncing the
VSCode-Portablefolder before launching VS Code—this avoids file conflicts. - Try not to open VS Code on multiple devices at the same time, as sync delays could cause settings/plugin discrepancies.
内容的提问来源于stack exchange,提问作者imhuay




