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

引用(来源)

相关推荐
玄同7651 天前
Trae国际版与国内版深度测评:AI原生IDE的双生花
ide·人工智能·ai编程·cursor·ai-native·trae
Jackson@ML1 天前
[Kimi重磅出击!]用Kimi Code智能高效开发Web应用程序指南
ide·python·kimi code
咕噜咕噜啦啦1 天前
ROS入门
linux·vscode·python
切糕师学AI1 天前
VSCode 下如何检查 Vue 项目中未使用的依赖?
vue.js·vscode
青椒*^_^*凤爪爪1 天前
Vscode下调试STM32N6系列单片机的方法
vscode·单片机·stm32n6·stm32n647
白日梦想家6811 天前
第三篇:Node.js 性能优化实战:提升服务并发与稳定性
linux·编辑器·vim
猿小猴子1 天前
主流 AI IDE 之一的 OpenCode 介绍
ide·人工智能·ai·opencode
万法若空1 天前
Vim常用指令汇编
汇编·编辑器·vim
量子炒饭大师2 天前
【一天一个计算机知识】—— VScode 极速搭建:打造你的全能代码武器库
ide·vscode·编辑器
程序员贵哥2 天前
彻底还原VSCode:Windows下完全重置VS Code配置的方法
vscode