Visual Studio immediate window command for Clear All

Visual StudioVisual Studio-2008Immediate Window

Visual Studio Problem Overview


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.

Visual Studio Solutions


Solution 1 - Visual Studio

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.

Solution 2 - Visual Studio

>cls 

seems to do it for me.

Solution 3 - Visual Studio

  1. Place the mouse cursor in the Immediate Window.
  2. Right click on the mouse and select "Clear All".

Solution 4 - Visual Studio

found it...

">Edit.ClearAll"

or

">cls"

Solution 5 - Visual Studio

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

Solution 6 - Visual Studio

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.

Solution 7 - Visual Studio

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

Solution 8 - Visual Studio

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionScott IveyView Question on Stackoverflow
Solution 1 - Visual Studiolc.View Answer on Stackoverflow
Solution 2 - Visual StudioMartin BrownView Answer on Stackoverflow
Solution 3 - Visual Studiorossco78View Answer on Stackoverflow
Solution 4 - Visual StudioScott IveyView Answer on Stackoverflow
Solution 5 - Visual Studiouser1330634View Answer on Stackoverflow
Solution 6 - Visual StudioMojtaba RezaeianView Answer on Stackoverflow
Solution 7 - Visual StudioWade HatlerView Answer on Stackoverflow
Solution 8 - Visual StudioRenjiView Answer on Stackoverflow