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

Visual Studio能否关闭除固定标签与当前选中标签外的所有标签?

Great question! I totally get the frustration of having to do two steps when you just want one clean action—closing everything except your pinned tabs and the one you're currently working on. Here are your best options to fix this in Visual Studio:

Option 1: Use a Pre-Built Extension (Quickest Fix)

  • Head to Extensions > Manage Extensions in Visual Studio, then search the Marketplace for terms like "Close All Except Pinned and Active" or "Tab Cleaner".
  • Look for extensions with high ratings and recent updates—many of these add a direct right-click option to your tabs labeled something like Close All But Pinned and Current.
  • Once installed and you restart VS, just right-click any tab, select that option, and it’ll instantly close every tab except your pinned ones and the active tab you’re on. No extra steps needed!

Option 2: Create a Custom Macro (No Extra Extension Dependency)

If you’d rather avoid adding another extension, you can build a simple macro to do this:

  1. First, install the Macros for Visual Studio extension (it lets you run custom C# scripts directly in VS).
  2. Open the Macro Explorer, create a new macro, and paste this code:
using EnvDTE;
using Microsoft.VisualStudio.Shell;

public void CloseAllExceptPinnedAndActive()
{
    var dte = (DTE)Package.GetGlobalService(typeof(DTE));
    foreach (Window window in dte.Windows)
    {
        if (window.Kind == "Document" && !window.IsPinned && window != dte.ActiveWindow)
        {
            window.Close(vsSaveChanges.vsSaveChangesPrompt);
        }
    }
}
  1. Save the macro, then go to Tools > Options > Keyboard to bind it to a keyboard shortcut (like Ctrl+Shift+Alt+C) for even faster access.

This script loops through all document windows, checks if they’re not pinned and not the active window, then closes them (prompting you to save unsaved changes if needed).


内容的提问来源于stack exchange,提问作者David S.

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 06:37:21