因为之前一直使用VS Code IDE,最近市面上也出现了很多基于 VS Code 内核二次开发的 IDE,本质上兼容 VS Code 的插件体系和配置体系。所以在使用的时候,根据自己的习惯,把自己写好的代码片段直接摘出来,便于自己在新的IDE上开发。
-
VS Code的代码片段配置
image.png
然后我需要导入到cursor或者CodeBuddy IDE,因为文件多,不想一个个又新建,所以想办法能不能一键同步,所以搞一个文件程序,把文件弄过去
const fs = require("fs");
const path = require("path");
const os = require("os");
function getSnippetPath(product) {
const platform = os.platform();
if (platform === "win32") {
return path.join(process.env.APPDATA, product, "User", "snippets");
} else if (platform === "darwin") {
return path.join(os.homedir(), "Library", "Application Support", product, "User", "snippets");
} else {
return path.join(os.homedir(), ".config", product, "User", "snippets");
}
}
function copySnippets(src, dest) {
if (!fs.existsSync(src)) {
console.error(`❌ 源目录不存在: ${src}`);
return;
}
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest, { recursive: true });
}
const files = fs.readdirSync(src);
files.forEach(file => {
if (file.endsWith(".json") || file.endsWith(".code-snippets")) {
const srcFile = path.join(src, file);
const destFile = path.join(dest, file);
fs.copyFileSync(srcFile, destFile);
console.log(`✅ 已同步: ${file}`);
}
});
}
const vscodePath = getSnippetPath("Code");
const codeBuddyPath = getSnippetPath("CodeBuddy");
console.log("🔄 开始同步 Snippets ...");
console.log(`VS Code 路径: ${vscodePath}`);
console.log(`CodeBuddy 路径: ${codeBuddyPath}`);
copySnippets(vscodePath, codeBuddyPath);
console.log("🎉 同步完成!");
然后在终端执行node
node sync-snippets.js
image.png
同步完成,然后在CodeBuddy IDE上看看
image.png
也是可以了,okk