Cursor配置迁移到VSCode

脚本说明

  • 编辑器设置 (settings.json):主题、字体、缩进、自动补全、终端设置等
  • 快捷键设置 (keybindings.json):自定义的操作快捷键
  • 代码片段 (snippets):个人创建的代码模板
  • 扩展插件:导出 Cursor 的扩展列表,并在 VSCode 官方扩展市场重新安装

cursor2vscode.ps1: (Windows-测试可用)

ps1 复制代码
# ============================================
# Cursor config & extensions migration to VSCode (Clean Version)
# ============================================

function Write-Info($msg) { Write-Host "✅ $msg" -ForegroundColor Green }
function Write-Warn($msg) { Write-Host "⚠️  $msg" -ForegroundColor Yellow }
function Write-ErrorMsg($msg) { Write-Host "❌ $msg" -ForegroundColor Red }

$cursorDir = "$env:APPDATA\Cursor\User"
$vscodeDir = "$env:APPDATA\Code\User"
$tempFile  = "$env:TEMP\cursor-extensions.txt"

function Test-Command($cmd) {
    return (Get-Command $cmd -ErrorAction SilentlyContinue) -ne $null
}

if (-not (Test-Command "cursor")) {
    Write-ErrorMsg "Command 'cursor' not found. Please install Cursor and add it to PATH."
    exit 1
}
if (-not (Test-Command "code")) {
    Write-ErrorMsg "Command 'code' not found. Please install VSCode and enable CLI tools."
    exit 1
}

Write-Info "Copying essential Cursor config to VSCode..."

if (Test-Path $cursorDir) {
    New-Item -ItemType Directory -Force -Path $vscodeDir | Out-Null

    # 需要复制的文件和文件夹
    $filesToCopy = @("settings.json", "keybindings.json")
    $dirsToCopy  = @("snippets")

    foreach ($f in $filesToCopy) {
        $src = Join-Path $cursorDir $f
        if (Test-Path $src) {
            Copy-Item -Force $src $vscodeDir
            Write-Info "Copied: $f"
        } else {
            Write-Warn "Not found: $f"
        }
    }

    foreach ($d in $dirsToCopy) {
        $src = Join-Path $cursorDir $d
        if (Test-Path $src) {
            Copy-Item -Recurse -Force $src $vscodeDir
            Write-Info "Copied folder: $d"
        } else {
            Write-Warn "Not found folder: $d"
        }
    }
} else {
    Write-Warn "Cursor config folder not found: $cursorDir"
}

# 导出扩展
Write-Info "Exporting Cursor extensions..."
cursor --list-extensions > $tempFile

# 安装扩展
Write-Info "Installing extensions to VSCode..."
Get-Content $tempFile | ForEach-Object {
    $ext = $_.Trim()
    if ($ext -ne "") {
        if (code --list-extensions | Select-String -SimpleMatch $ext) {
            Write-Warn "Already installed, skipped: $ext"
        } else {
            code --install-extension $ext | Out-Null
            if ($LASTEXITCODE -eq 0) {
                Write-Info "Installed: $ext"
            } else {
                Write-ErrorMsg "Failed to install: $ext"
            }
        }
    }
}

Remove-Item $tempFile -Force

Write-Info "Migration completed (settings, keybindings, snippets, extensions)!"

cursor2vscode.bash: (Linux-未测试)

bash 复制代码
#!/usr/bin/env bash
set -e

# 提示函数
info()  { echo -e "✅ $1"; }
warn()  { echo -e "⚠️  $1"; }
error() { echo -e "❌ $1"; exit 1; }

# 不同系统下 Cursor / VSCode 的配置路径
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
    cursorDir="$HOME/.config/Cursor/User"
    vscodeDir="$HOME/.config/Code/User"
    tempFile="/tmp/cursor-extensions.txt"
elif [[ "$OSTYPE" == "darwin"* ]]; then
    cursorDir="$HOME/Library/Application Support/Cursor/User"
    vscodeDir="$HOME/Library/Application Support/Code/User"
    tempFile="/tmp/cursor-extensions.txt"
else
    error "Unsupported OS: $OSTYPE"
fi

# 检查命令是否存在
command -v cursor >/dev/null 2>&1 || error "Command 'cursor' not found. Add it to PATH."
command -v code   >/dev/null 2>&1 || error "Command 'code' not found. Enable VSCode CLI."

info "Copying essential Cursor config to VSCode..."
mkdir -p "$vscodeDir"

# 需要复制的文件和文件夹
filesToCopy=("settings.json" "keybindings.json")
dirsToCopy=("snippets")

for f in "${filesToCopy[@]}"; do
    if [[ -f "$cursorDir/$f" ]]; then
        cp -f "$cursorDir/$f" "$vscodeDir/"
        info "Copied: $f"
    else
        warn "Not found: $f"
    fi
done

for d in "${dirsToCopy[@]}"; do
    if [[ -d "$cursorDir/$d" ]]; then
        cp -r "$cursorDir/$d" "$vscodeDir/"
        info "Copied folder: $d"
    else
        warn "Not found folder: $d"
    fi
done

# 导出扩展
info "Exporting Cursor extensions..."
cursor --list-extensions > "$tempFile"

# 安装扩展到 VSCode
info "Installing extensions to VSCode..."
while IFS= read -r ext; do
    if [[ -n "$ext" ]]; then
        if code --list-extensions | grep -q "$ext"; then
            warn "Already installed, skipped: $ext"
        else
            if code --install-extension "$ext"; then
                info "Installed: $ext"
            else
                error "Failed to install: $ext"
            fi
        fi
    fi
done < "$tempFile"

rm -f "$tempFile"
info "Migration completed (settings, keybindings, snippets, extensions)!"

路径正确性测试 (Windows)

bash 复制代码
code --version
cursor --version

测试脚本:

ps1 复制代码
# 定义路径
$cursorDir = "$env:APPDATA\Cursor\User"
$vscodeDir = "$env:APPDATA\Code\User"

# 打印路径具体位置
Write-Host "Cursor 路径: $cursorDir"
Write-Host "VSCode 路径: $vscodeDir"

# 测试路径是否存在
if (Test-Path $cursorDir) {
    Write-Host "✅ Cursor 配置文件夹存在" -ForegroundColor Green
} else {
    Write-Host "❌ 找不到 Cursor 配置文件夹" -ForegroundColor Red
}

if (Test-Path $vscodeDir) {
    Write-Host "✅ VSCode 配置文件夹存在" -ForegroundColor Green
} else {
    Write-Host "❌ 找不到 VSCode 配置文件夹" -ForegroundColor Red
}

注意事项

如果你打算运行这段代码,请注意以下几点:

  • 覆盖风险: 脚本使用了 Copy-Item -Force,这意味着它会直接覆盖你现有的 VS Code 配置文件 (settings.json 和 keybindings.json)。如果你在 VS Code 里有不想丢失的独特配置,请先备份。
  • 兼容性: 虽然大部分配置通用,但 Cursor 特有的设置(如 AI 相关的 Copilot 设置)在 VS Code 中可能会被识别为"未知配置"并显示警告(通常不影响使用)。
  • 插件差异: 极少数 Cursor 专用插件可能无法在 VS Code 插件市场找到,从而导致安装失败(脚本会提示错误但继续运行)。

引用(来源)

相关推荐
徐小夕@趣谈前端7 小时前
拒绝重复造轮子?我们偏偏花365天,用Vue3写了款AI协同的Word编辑器
人工智能·编辑器·word
风一样的航哥7 小时前
标题:从卡顿到流畅:深度剖析 Word 2013 与 Word 2021 处理高清图片文档的性能鸿沟
编辑器
冬奇Lab11 小时前
一天一个开源项目(第14篇):CC Workflow Studio - 可视化AI工作流编辑器,让AI自动化更简单
人工智能·开源·编辑器
开源技术12 小时前
Python GeoPandas基础知识:地图、投影和空间连接
开发语言·ide·python
暴走十八步13 小时前
PHP+vscode开启调试debug
开发语言·vscode·php
承渊政道13 小时前
Linux系统学习【Linux基础开发工具】
linux·运维·笔记·学习·centos·编辑器
you-_ling13 小时前
IO编程相关知识
c语言·vscode
学嵌入式的小杨同学1 天前
【Linux 封神之路】信号编程全解析:从信号基础到 MP3 播放器实战(含核心 API 与避坑指南)
java·linux·c语言·开发语言·vscode·vim·ux
寻梦csdn1 天前
pycharm+miniconda兼容问题
ide·python·pycharm·conda
徐小夕@趣谈前端1 天前
Web文档的“Office时刻“:jitword共建版2.0发布!让浏览器变成本地生产力
前端·数据结构·vue.js·算法·开源·编辑器·es6