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

如何在Visual Studio Code运行代码前自动清除终端内容?

Fixing VS Code Terminal Auto-Clear for Code Runs

Hey there! I totally get how annoying it is to dig through old terminal output every time you run your code—PyCharm’s auto-clear feature sets a high bar, right? Let’s get this sorted for your VS Code Education Edition.

First, let’s break down solutions based on how you’re running your code:

  • If you’re using the Code Runner extension (the common "Run Code" button in the top right):

    1. Open the Command Palette by pressing Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (Mac).
    2. Type Preferences: Open Settings (JSON) and hit enter—this opens the raw settings file, which lets us bypass any UI search gaps.
    3. Add this line inside the curly braces of the JSON object (make sure commas are correctly placed if you have existing settings):
      "code-runner.clearPreviousOutput": true
      
    4. Save the file, and next time you click "Run Code", the terminal will clear old output before running your new code.
  • If you’re using VS Code’s built-in Python run/debug tools instead of Code Runner:

    1. Open the Command Palette again and select Preferences: Open Settings (UI).
    2. Search for Terminal: Clear Before Executing and check the box. This will make the terminal auto-clear every time you start a run or debug session.

A quick heads-up: Sometimes UI setting searches can miss options due to extension versions or edition-specific tweaks, so going straight to the JSON settings is a reliable workaround.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.30 13:57:39