最可靠方式是手动导出settings.json、keybindings.json和snippets目录,并用code --list-extensions导出扩展列表;需按系统路径定位文件,清理绝对路径与平台专属字段,避免静默失效。

直接导出 settings.json 和 keybindings.json 文件是最可靠的方式,但必须清理绝对路径和平台专属字段,否则在新机器上大概率静默失效。
怎么找到真实的 settings.json 和 keybindings.json 路径
这两个文件不在 VSCode 安装目录里,硬翻 Program Files 或 Applications/Visual Studio Code.app 会扑空。真实路径由系统决定:
- Windows:
%APPDATA%\Code\User\settings.json(文件资源管理器地址栏粘贴即可直达) - macOS:
~/Library/Application Support/Code/User/settings.json(终端执行open ~/Library/Application\ Support/Code/User快速打开) - Linux:
~/.config/Code/User/settings.json
别用「设置 → 打开设置 (JSON)」后全选复制内容——那只是 UI 渲染快照,会丢注释、格式错乱,且不包含显式设为 false 的禁用项(比如 "editor.minimap.enabled": false 在 UI 里根本不显示,但它有效)。
导出前必须删掉或注释的三类危险字段
直接拷贝原 settings.json 到新机器,VSCode 启动时可能静默跳过整行,甚至回退到默认配置。重点处理:
-
"python.defaultInterpreterPath"、"python.condaPath":指向本机解释器,换电脑后路径必不存在 -
"files.exclude"或"search.exclude"中含C:\Users\、/home/、/Users/这类绝对路径 -
"terminal.integrated.profiles.windows"、"terminal.integrated.fontFamily"等平台专属配置:跨系统导入可能触发警告甚至阻断加载
建议在 VSCode 里用 Ctrl+F 全局搜索 ": " 后跟引号内含路径或平台关键词的行,逐条删或加 // 注释。
keybindings.json 导出要注意 when 条件和扩展依赖
快捷键是否生效,不只看 key 和 command,更取决于 when 字段能否满足。比如:
-
"when":"editorTextFocus && todo-tree.tree.showScanModeButton":如果目标机器没装todo-tree插件,这行整个被忽略 -
"when":"terminalFocus && terminalProcessSupported":WSL 或 Remote-SSH 环境下可能不满足
导出时务必确认:keybindings.json 是合法 JSON 数组(如 [{"key":"ctrl+alt+l","command":"editor.action.formatDocument","when":"editorTextFocus"}]),且只包含用户自定义部分;空数组 [] 表示当前无自定义项,别误以为导出失败。
扩展列表必须单独导出,不能靠配置文件推断
settings.json 和 keybindings.json 不包含“已启用扩展”信息。必须用命令行导出:
- 运行
code --list-extensions --show-versions > extensions.txt,得到形如ms-python.python@2026.10.1的列表 - 导入时,在新机器上执行
cat extensions.txt | xargs -L 1 code --install-extension(Linux/macOS)或用 PowerShellGet-Content extensions.txt | ForEach-Object { code --install-extension $_ }
注意:code --install-extension 不会自动启用插件,安装后需重启 VSCode 或手动启用;若用了 Remote-SSH,还需同步远程侧的 ~/.vscode-server/data/Machine/settings.json 和扩展。
最易被忽略的是:VSCode 启动时若检测到 JSON 格式错误(比如 BOM、\r\n 换行符、多了一个逗号),会静默放弃整个 settings.json 并回退到默认值——所以导入前务必用 VSCode 自己打开该文件并保存一次,确保格式干净。











