You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code 终端如何隐藏运行代码时的目录路径并实现运行前自动清屏

VS Code 运行代码冗余提示消除与自动清屏配置

消除执行代码时弹出的c:\directory类路径提示

这类提示是Code Runner插件默认开启的执行信息展示功能带出来的,关掉对应开关就行:

  • 打开VS Code设置面板,快捷键为Ctrl+,,或点击左侧边栏底部的齿轮图标选择「设置」
  • 在设置搜索框输入code-runner.showExecutionMessage,取消该选项的勾选
  • 如果习惯直接编辑全局配置文件settings.json,直接添加对应配置项即可:
    "code-runner.showExecutionMessage": false

实现点击运行前自动清空上一次终端输出

要实现点击运行按钮时,自动先执行CLS清屏、再跑代码的效果,需要先让Code Runner把代码输出引导到VS Code的集成终端里,再调整对应语言的执行命令:

  • 同样在设置中搜索code-runner.runInTerminal,勾选该选项,确保运行代码的输出直接在集成终端展示,而不是插件自带的输出面板(自带输出面板不支持执行系统清屏命令)
  • 搜索code-runner.executorMap,找到你日常使用的编程语言对应的执行命令,在命令最前面加上cls; 前缀,常见语言的配置参考:
    • Python:原执行命令python -u修改为cls; python -u
    • C语言:原执行命令cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt修改为cls; cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt
    • C++:原执行命令cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt修改为cls; cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt
  • 直接修改配置文件的话,对应配置片段参考:
"code-runner.runInTerminal": true,
"code-runner.executorMap": {
    "python": "cls; python -u",
    "c": "cls; cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
    "cpp": "cls; cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
}

注意:CLS是Windows系统命令行的清屏指令,如果使用Mac/Linux系统,将命令中的cls替换为clear即可生效。

内容的提问来源于stack exchange,提问作者Blocked User

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.22 13:57:03