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

引用(来源)

相关推荐
VidDown4 天前
VidDown 工具站:免费、本地优先的开发者工具箱
javascript·编辑器·音视频·视频编解码·视频
摇滚侠4 天前
IDEA 创建 Java 项目 手动整合 SSM 框架
java·ide·intellij-idea
霸道流氓气质4 天前
Trae IDE 新手入门指南
ide
VidDown4 天前
显卡处理视频技术详解:从硬解码到 NVENC,GPU 如何让视频处理起飞?
javascript·编辑器·音视频·视频编解码·视频
王小二AI4 天前
baoyu-skills 实战:22 个 AI 技能,从采集到发布一句话搞定
ai编程·cursor
夜猫逐梦4 天前
【UE基础】03.蓝图与编辑器工作流
编辑器·ue·蓝图·ue编辑器
VidDown4 天前
视频帧率技术详解:从 24fps 到 120fps,帧率如何影响你的观看体验?
网络·网络协议·编辑器·音视频·视频编解码·视频
爱就是恒久忍耐4 天前
VSCode里如何比较2个branch
ide·vscode·编辑器
意法半导体STM324 天前
【官方原创】如何为STM32CubeMX2配置Visual Studio Code配置方案
vscode·stm32·单片机·嵌入式硬件·策略模式·stm32cubemx·嵌入式开发
bloglin999994 天前
vscode中可视化的合并分支,在“合并编辑器中解析”中“与基线进行比较”是什么意思
ide·vscode·编辑器