用于清除全部的 Visual Studio 立即窗口命令

发布于 2024-07-16 11:41:46 字数 79 浏览 11 评论 0原文

Visual Studio 中有清除立即窗口的命令吗?

我讨厌必须抓住鼠标右键单击菜单 - 宁愿只输入“cls”或其他东西。

Is there a command to clear the immediate window in Visual Studio?

I hate having to grab the mouse for a right click menu there - would rather just type "cls" or something.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

此刻的回忆 2024-07-23 11:41:46

要清除即时窗口,您可以使用 >cls,它是预定义的 命令别名>Edit.ClearAll

MSDN 文章列出了所有预定义的别名,您也可以定义自己的别名。 (对于 VS 2010 及更早版本,自定义别名 不过,在另一篇文章中进行了描述。)浏览一下,就会发现有很多这样的问题,其中一些甚至可能源于 MS-DOS DEBUG.EXE(特别是 >d、<我想到了 code>>g、>p>q 和 >t)。


另外值得注意的是,因为只需按两个键:上下文菜单> 全部清除会调用相同的命令,并且可以使用键盘进行导航。 因此,在立即窗口中,您可以按上下文菜单L

如果您的键盘上没有上下文菜单 (您知道,右 Alt右 Ctrl 之间的那个),您可以使用 Shift+F10 代替。

To clear the immediate window, you can use >cls, which is a predefined command alias to >Edit.ClearAll.

The MSDN article lists all predefined aliases and you can define your own, too. (For VS 2010 and earlier, custom aliases are described in a separate article, though.) Scanning through, there's a whole slew of them, some of which might even have their roots in MS-DOS DEBUG.EXE (specifically >d, >g, >p, >q, and >t come to mind).


Also worth noting as it's only two keys to press: Context menu > Clear All invokes the same command and it can be navigated using keyboard. Therefore in the immediate window, you can press Context Menu, L.

If you don't have a context-menu key on your keyboard (you know, the one between Right Alt and Right Ctrl), you can use Shift+F10 instead.

梦里梦着梦中梦 2024-07-23 11:41:46
>cls 

似乎是为我做的。

>cls 

seems to do it for me.

雨落星ぅ辰 2024-07-23 11:41:46
  1. 将鼠标光标放在立即窗口中。
  2. 右键单击鼠标并选择“全部清除”。
  1. Place the mouse cursor in the Immediate Window.
  2. Right click on the mouse and select "Clear All".
韶华倾负 2024-07-23 11:41:46

找到它...

“>Edit.ClearAll”

“>cls”

found it...

">Edit.ClearAll"

or

">cls"

等数载,海棠开 2024-07-23 11:41:46

以下是在运行时执行此操作的方法:

  1. 在您的应用程序中引用 EnvDTE dll。

  2. 根据需要创建并使用此函数。

Public Sub ClearImmediateWindow()
  Try
    Dim vsWindowKindImmediateWindow As String _ 
          = "{ECB7191A-597B-41F5-9843-03A4CF275DDE}"
    Try
      Dim obj As Object = System.Runtime.InteropServices.Marshal._ 
                          GetActiveObject("VisualStudio.DTE.10.0")
      If obj IsNot Nothing Then
        Dim DTE2 As EnvDTE80.DTE2 = CType(obj, EnvDTE80.DTE2)
        For Each wndw As EnvDTE.Window In DTE2.Windows
          If wndw.ObjectKind = vsWindowKindImmediateWindow Then
            wndw.Activate()
            DTE2.ExecuteCommand("Edit.ClearAll")
            Exit For
          End If
        Next
      End If
    Catch comEx As COMException
      ' Not running from within the VS IDE?
    Catch ex As Exception
      Throw ex
    End Try
  Catch ex As Exception
    ' Handle this as you desire.
  End Try
End Sub
  End Sub

Here is how to do it at run time:

  1. Reference the EnvDTE dlls in your application.

  2. Create and then use this function as necessary.

Public Sub ClearImmediateWindow()
  Try
    Dim vsWindowKindImmediateWindow As String _ 
          = "{ECB7191A-597B-41F5-9843-03A4CF275DDE}"
    Try
      Dim obj As Object = System.Runtime.InteropServices.Marshal._ 
                          GetActiveObject("VisualStudio.DTE.10.0")
      If obj IsNot Nothing Then
        Dim DTE2 As EnvDTE80.DTE2 = CType(obj, EnvDTE80.DTE2)
        For Each wndw As EnvDTE.Window In DTE2.Windows
          If wndw.ObjectKind = vsWindowKindImmediateWindow Then
            wndw.Activate()
            DTE2.ExecuteCommand("Edit.ClearAll")
            Exit For
          End If
        Next
      End If
    Catch comEx As COMException
      ' Not running from within the VS IDE?
    Catch ex As Exception
      Throw ex
    End Try
  Catch ex As Exception
    ' Handle this as you desire.
  End Try
End Sub
  End Sub
后知后觉 2024-07-23 11:41:46

对于 Visual Studio 2012,我使用:

Public Sub ClearImmediateWindow()
    Dim dte As EnvDTE80.DTE2 = Marshal.GetActiveObject("VisualStudio.DTE.11.0")
    dte.Windows.Item("Immediate Window").Activate() 'Activate Immediate Window  
    dte.ExecuteCommand("Edit.SelectAll")
    dte.ExecuteCommand("Edit.ClearAll")
    Marshal.ReleaseComObject(dte)
End Sub

自动清除代码中的即时窗口(需要向项目添加 DTE 引用)。 如果它不起作用,请根据您的 Visual Studio 版本尝试 VisualStudio.DTE.8.0VisualStudio.DTE.9.0...

For visual studio 2012 I use:

Public Sub ClearImmediateWindow()
    Dim dte As EnvDTE80.DTE2 = Marshal.GetActiveObject("VisualStudio.DTE.11.0")
    dte.Windows.Item("Immediate Window").Activate() 'Activate Immediate Window  
    dte.ExecuteCommand("Edit.SelectAll")
    dte.ExecuteCommand("Edit.ClearAll")
    Marshal.ReleaseComObject(dte)
End Sub

to automatically clear immediate window from codes(requires to add DTE references to project). If it not works try VisualStudio.DTE.8.0, VisualStudio.DTE.9.0, ... according to your visual studio version.

最佳男配角 2024-07-23 11:41:46

我逐字地使用了最后一个答案,它有效,尽管我希望将焦点放回原来的位置。 这是稍微改进的 C# 版本。 我通过配置开关启用它。

#if DEBUG
    if (GetIni("Debug", "ClearImmediateWindow", true)) {
        try {
            var dte = (EnvDTE.DTE) Marshal.GetActiveObject("VisualStudio.DTE.15.0");
            var me  = dte.ActiveWindow;
            dte.Windows.Item("Immediate Window").Activate();
            dte.ExecuteCommand("Edit.ClearAll");
            me.Activate();
        }
        catch { /* Meh! */ }
#endif

I used the last answer just about verbatim and it works, although I wanted the focus back on where it was. Here's the very slightly improved C# version. I enable it with a configuration switch.

#if DEBUG
    if (GetIni("Debug", "ClearImmediateWindow", true)) {
        try {
            var dte = (EnvDTE.DTE) Marshal.GetActiveObject("VisualStudio.DTE.15.0");
            var me  = dte.ActiveWindow;
            dte.Windows.Item("Immediate Window").Activate();
            dte.ExecuteCommand("Edit.ClearAll");
            me.Activate();
        }
        catch { /* Meh! */ }
#endif
2024-07-23 11:41:46

如果您想知道如何在 Visual Studio Mac 上清除即时窗口,只需右键单击窗口内部并选择选项清除

Those who are wondering how to clear immediate window on Visual Studio Mac, just right click inside the window and select the option Clear

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文