Command Mode, Command Window
The Command mode of the Command window is used for executing commands or aliases directly in the Visual Studio .NET environment, bypassing the menu system, or for executing commands that do not appear on any menu.
In Command mode, statements separated by the equal sign (=) are evaluated as comparison operators. For example, if the value of variables a
and b
are different, then >? a = b
returns a value of False. In Immediate mode, however, the statement a=b
is evaluated as an assignment operation rather than a comparison operation. That is, a=b
assigns the value of variable a
to the value of variable b
. You cannot use assignment operations in Command mode.
Open the Command window in Command mode by pressing CTRL+ALT+A, or by choosing Command Window on the Other Windows submenu of the View menu. When the Command window is in Command mode, its title bar displays the text Command Window
and the greater than symbol (>
) appears in the window as a prompt for new lines.
Note Commands typed in Command mode are not prefaced by the greater than sign (>) because it is the command prompt in that mode. You must enter the greater than sign (>), however, when issuing Visual Studio .NET commands while in Immediate mode.
Task | Solution | Example |
---|---|---|
Evaluate expressions in Command mode. | Preface the expression with a question mark (? ). |
?myvar |
Switch to Immediate mode from Command mode. | Enter immed into the window without the greater than sign (>) |
immed |
Switch back to Command mode from Immediate mode. | enter cmd into the window. |
>cmd |
The following keys help you navigate while in Command mode.
Action | Cursor location | Keybinding |
---|---|---|
Cycle through the list of previously entered commands. | Input line | UP ARROW & DOWN ARROW |
Scroll up the window. | Command window contents | CTRL+UP ARROW |
Scroll down the window. | Command window contents | DOWN ARROW or CTRL+DOWN ARROW |
Tip You can copy all or part of a previous command to the input line by scrolling to it, highlighting all or part of it, and then pressing ENTER.
Parameters, Switches, and Values
Some Visual Studio .NET commands have required and optional arguments, switches and values. Certain rules apply when dealing with such commands. The following is an example of a rich command to clarify the terminology.
Edit.ReplaceInFiles /case /pattern:regex var[1-3]+ oldpar
In this example,
Edit.ReplaceInFiles
is the command/case
and/pattern:regex
are switches (prefaced with the slash [/] character)regex
is the value of the/pattern
switch; the/case
switch has no valuevar[1-3]+
andoldpar
are parametersNote Any command, parameter, switch, or value that contains spaces must have double quotation marks on either side.
The position of switches and parameters can be interchanged freely on the command line with the exception of the Shell command, which requires its switches and parameters in a specific order.
Nearly every switch supported by a command has two forms: a short (one character) form and a long form. Multiple short-form switches can be combined into a group. For example, /p /g /m
can be expressed alternately as /pgm
.
If short-form switches are combined into a group and given a value, that value applies to every switch. For example, /pgm:123
equates to /p:123 /g:123 /m:123
. An error occurs if any of the switches in the group does not accept a value.
Escape Characters
A caret (^) character in a command line means that the character immediately following it is interpreted literally, rather than as a control character. This can be used to embed straight quotation marks ("), spaces, leading slashes, carets, or any other literal characters in a parameter or switch value, with the exception of switch names. For example,
>Edit.Find ^^t /regex
A caret functions the same whether it is inside or outside quotation marks. If a caret is the last character on the line, it is ignored.
Mark Mode
Mark mode in the Command window allows you to select, copy, and paste text in it or to re-execute previous commands. Enter Mark mode by clicking on a previous line in the Command window (in either Command or Immediate mode), or by choosing Mark Mode from the context menu, or by pressing CTRL + SHIFT + M. Once in Mark mode, you can use either the context commands or their keyboard equivalents to cut, copy, paste, or clear text in the window.
See Also
Command Window | Immediate Mode, Command Window | Pre-defined Visual Studio Command Aliases | Regular Expressions | Shell Command