运行JavaScript时VS Code为何会启动名为code的新终端?
解决VS Code运行JavaScript时重复新建终端的问题
核心配置修正
要让Code Runner复用默认的PowerShell终端,需要补充两个关键配置,并修正原有配置的语法错误:
- 指定默认终端为PowerShell
在配置中添加以下项,绑定你已定义的PowerShell终端为默认:
"terminal.integrated.defaultProfile.windows": "PowerShell"
- 开启Code Runner终端复用
添加这个配置,阻止Code Runner每次运行代码时新建终端:
"code-runner.reuseTerminal": true
- 修复原有配置的语法错误
你原来的配置里,"terminal.integrated.profiles.windows"块末尾缺少逗号,导致JSON格式无效,必须补上才能让配置生效。
完整工作区配置示例
修正后的完整配置如下:
{ "terminal.integrated.profiles.windows": { "PowerShell": { "source": "PowerShell", "icon": "terminal-powershell" }, "Command Prompt": { "path": [ "${env:windir}\\Sysnative\\cmd.exe", "${env:windir}\\System32\\cmd.exe" ], "args": [], "icon": "terminal-cmd" }, "Git Bash": { "source": "Git Bash" }, "Windows PowerShell": { "path": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" } }, "terminal.integrated.defaultProfile.windows": "PowerShell", "code-runner.runInTerminal": true, "code-runner.clearPreviousOutput": false, "code-runner.reuseTerminal": true, "code-runner.executorMap": { "javascript": "node", "java": "cd $dir && javac $fileName && java $fileNameWithoutExt", "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt" } }
验证方式
保存配置后,打开一个PowerShell终端(未自动打开的话手动新建),运行JavaScript代码,此时代码会在已有的PowerShell终端中执行,不会再生成名为code的新终端。
内容的提问来源于stack exchange,提问作者Richard Mwambanga
相关产品推荐
相关产品推荐

