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

如何移除VS Code终端中的多余文本?修改settings.json无效

移除终端中运行程序的路径,让输出更整洁

如果是VS Code终端里的提示符或运行代码时的路径显示问题,按以下场景处理:

1. 修改终端提示符,去掉冗长路径

针对不同系统的终端shell,在settings.json中添加对应配置:

Windows PowerShell

"terminal.integrated.profiles.windows": {
  "PowerShell": {
    "source": "PowerShell",
    "args": ["-NoLogo", "-Command", "$prompt = '$ '"]
  }
},
"terminal.integrated.defaultProfile.windows": "PowerShell"

-NoLogo会去掉PowerShell启动时的版权信息,$prompt = '$ '将提示符简化为$ ,你可以改成任意喜欢的符号(比如> )。

Linux/macOS bash

"terminal.integrated.profiles.linux": {
  "bash": {
    "source": "bash",
    "args": ["--noprofile", "--norc", "-c", "PS1='$ '; exec bash"]
  }
},
"terminal.integrated.defaultProfile.linux": "bash"

macOS zsh

"terminal.integrated.profiles.osx": {
  "zsh": {
    "source": "zsh",
    "args": ["-c", "PS1='$ '; exec zsh"]
  }
},
"terminal.integrated.defaultProfile.osx": "zsh"

配置后重启VS Code终端,提示符就会变成简洁样式,不再显示完整路径。

2. 移除代码运行时的脚本路径输出

如果是运行代码(比如Python)时终端显示了脚本的完整路径,修改Python扩展配置:
在settings.json中添加:

"python.terminal.executeInFileDir": false,
"python.terminal.launchArgs": ["-c", "import sys; exec(open(sys.argv[1]).read())"]

或者修改.vscode/launch.json的运行配置,确保只输出程序运行结果:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Current File",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal",
      "env": {"PS1": "$ "}
    }
  ]
}

注意事项

  • 确保settings.json中的配置没有语法错误(比如逗号遗漏),否则配置不会生效。
  • 修改后需要重启VS Code或重新打开终端,让配置生效。

内容的提问来源于stack exchange,提问作者yaseen wazir

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 01:54:26