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 插件市场找到,从而导致安装失败(脚本会提示错误但继续运行)。

引用(来源)

相关推荐
布鲁飞丝10 小时前
从零实现富文本编辑器#-浏览器选区与编辑器选区模型同步
java·前端·编辑器
计算机内卷的N天10 小时前
CMake与Visual Studio的使用
c++·ide·visual studio
咱入行浅11 小时前
一款实用的 Visual Studio 发布部署插件,助力提高部署效率!
ide·visual studio
谢斯11 小时前
[vscode] 使用unity打开vscode的取消.csproj的显示
ide·vscode·unity
2501_916007471 天前
SwiftUI 声明式语法与 Xcode 预览功能详解
ide·vscode·ios·swiftui·个人开发·xcode·敏捷流程
呐抹倾1 天前
【译】Visual Studio 停用:针对旧版本 Visual Studio 的支持提醒
ide·visual studio
爱就是恒久忍耐1 天前
使用VSCode开发STM32 (通用版本)
ide·vscode·stm32
FlightYe1 天前
音视频修炼之视频基础(一):视频基础理论
android·c++·vscode·音视频·androidx·android runtime
我要见SA姐11 天前
VsCode 使用指南(配置 + 美化)
ide·vscode·编辑器
魔尔助理顾问1 天前
安装 Jupyter Notebook (推荐给 venv 用户)
开发语言·ide·python·jupyter