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.
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.
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.
Here is how to do it at run time:
Reference the EnvDTE dlls in your application.
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
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! */ }
Those who are wondering how to clear immediate window on Visual Studio Mac, just right click inside the window and select the option Clear