VS Code / Cursor 将默认终端设置为 CMD 完整指南
文章目录
- 🧭 适用范围
- 📌 背景与问题分析
- 🛠 配置步骤
- 1. 打开设置(settings.json)
- 2. 添加或更新配置
- 3. 重启终端与编辑器
- 💡 补充:支持多个终端配置
- 🧯 常见问题排查
- ✅ 总结
在 Windows 系统上,开发者有时更倾向于使用 命令提示符(CMD) 而非默认的 PowerShell。而 Visual Studio Code(以下简称 VS Code)及其衍生版本(如 Cursor IDE)默认使用 PowerShell 作为集成终端。
即使设置了:
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe"
终端仍可能不会按预期使用 CMD。这是由于 VS Code 自 1.56 起引入了全新的 终端配置机制(Terminal Profiles),该机制已逐步取代旧有的 shell.windows
设置。
本文将介绍在 VS Code 和 Cursor 等编辑器 中,通过推荐的现代配置方式将默认终端设置为 CMD。
🧭 适用范围
- 操作系统:Windows 10 / 11
- 编辑器:Visual Studio Code、Cursor IDE 及其他基于 VS Code 构建的衍生 IDE
📌 背景与问题分析
旧方式(已过时):
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe"
这种方式已被弃用,可能在新版中被忽略。正确的做法是使用以下两个配置项:
terminal.integrated.profiles.windows
:注册不同终端的可选配置terminal.integrated.defaultProfile.windows
:指定默认使用的终端类型
🛠 配置步骤
1. 打开设置(settings.json)
- VS Code / Cursor 左下角点击齿轮图标 → “设置”
- 或使用快捷键
Ctrl + ,
打开设置界面 - 右上角点击 “打开设置(JSON)”,进入
settings.json
2. 添加或更新配置
在 settings.json
中添加以下内容:
{// 定义终端配置文件(Profiles)"terminal.integrated.profiles.windows": {"Command Prompt": {"path": "C:\\Windows\\System32\\cmd.exe","args": []},"PowerShell": {"source": "PowerShell"}},// 设置默认终端为 CMD"terminal.integrated.defaultProfile.windows": "Command Prompt",// 可选设置:自动保存等"files.autoSave": "afterDelay"
}
✅ 注意:路径应使用双反斜杠(
\\
),否则 JSON 将解析错误。
3. 重启终端与编辑器
完成设置后,建议执行以下操作:
- 关闭所有当前打开的终端窗口
- 重启 VS Code 或 Cursor
- 再次打开终端,终端应默认使用 CMD(命令提示符)
💡 补充:支持多个终端配置
以下是一个同时支持 CMD、PowerShell、Git Bash、WSL 的完整示例:
{"terminal.integrated.profiles.windows": {"Command Prompt": {"path": "C:\\Windows\\System32\\cmd.exe"},"PowerShell": {"source": "PowerShell"},"Git Bash": {"path": "C:\\Program Files\\Git\\bin\\bash.exe","args": ["--login", "-i"]},"WSL": {"path": "C:\\Windows\\System32\\wsl.exe"}},"terminal.integrated.defaultProfile.windows": "Command Prompt","files.autoSave": "afterDelay"
}
可通过 VS Code 左下角终端选择器,快速切换不同终端。
🧯 常见问题排查
问题 | 原因 | 解决方法 |
---|---|---|
修改配置后仍是 PowerShell | 旧配置被忽略,新配置未生效 | 确保使用 defaultProfile.windows 和 profiles.windows |
设置无效 | 被工作区级别的设置覆盖 | 检查项目根目录下的 .vscode/settings.json |
CMD 启动失败或找不到路径 | 配置路径错误 | 使用 C:\\Windows\\System32\\cmd.exe 且双反斜杠格式正确 |
启动时想执行命令 | 未添加启动参数 | 使用 "args": ["/k", "echo Hello CMD"] |
✅ 总结
配置项 | 说明 |
---|---|
terminal.integrated.profiles.windows | 定义终端种类和路径 |
terminal.integrated.defaultProfile.windows | 指定默认使用的终端 |
支持多个终端类型 | ✅ CMD / PowerShell / Git Bash / WSL |
适用编辑器 | ✅ VS Code / Cursor / Code OSS 等基于 VS Code 的工具 |
是否替代旧配置方式 | ✅ 是,新版本推荐使用 Profiles |