次の方法で共有


Understanding Commands: Arguments and Switches

Keyboard:  CTRL + ALT + A
Menu:  View -> Other Windows -> Command Window
Command:  View.CommandWindow
Versions:  2008,2010
Published:  8/10//2010
Code:  vstipTool0069

 

Folks I want to get your input on the possible title for the new book.  Give me your comments at https://blogs.msdn.com/b/zainnab/archive/2010/08/09/proposed-book-title.aspx

 

Some commands take arguments and switches so you can quickly execute them without having to deal with UI elements.  You can get a list of commands that take arguments by going to the MSDN Documentation article entitled "Visual Studio Commands with Arguments" (https://msdn.microsoft.com/en-us/library/c338aexd.aspx).  The best way to learn is by doing a sample so let's use the Edit.Find command.  If you want to know more about what Find can do then check out vstipFind0007.

 

Basic Use

First, open up the Command window (CTRL + ALT + A) and run the command without any arguments:

image

 

This will show the Find dialog:

image

 

 

 

Arguments and Switches

According to the documentation (https://msdn.microsoft.com/en-us/library/295dhke9.aspx), the Edit.Find command takes one argument and twelve possible switches.  The general syntax for the command is:

 

Edit.Find findwhat [/case] [/doc | /proc | /open | /sel] [/markall] [/options] [/reset] [/up] [/wild | /regex] [/word]

 

I'll resist the urge to copy and paste the documentation here and just focus on the items we are going to use:

 

Argument

findwhat

Required. The text to match.

 

Switches

/doc or /d

Optional. Searches the current document only. Specify only one of the available search scopes, /doc, /proc, /open, or /sel.

 

/markall or /m

Optional. Places a [bookmark] on each line that contains a search match within the current document.

 

/wild or /l

Optional. Uses pre-defined special characters in the findwhat argument as notations to represent a character or sequence of characters. For a complete list of wildcard characters.

 

 

 

List Current Options

You can list out the current options that are set for the Edit.Find command by typing "Edit.Find /options":

image

 

 

 

Reset Options

You can reset the options to the default values by typing "Edit.Find /reset":

image

 

 

 

Using the Arguments and Switches

Okay so let's put this sucker to the test.  We want to bypass the Quick Find dialog and just find stuff.  Here is the command we will use:

 

Edit.Find *c* /wild /doc /markall

 

This command will find any line in the current document (/doc) that has the letter "c" using wildcards (/wild) and placing a bookmark (/markall) on each line.

 

Here is the code we are going to use before we run the command:

image

 

We run our command:

image

 

And here is the result:

image

 

And now we have a working command that bypasses the Quick Find dialog and just finds stuff when we need it.

 

 

Make an Alias

What if we use want to use this all the time?  Simple!  We make an alias out of the command.  In this case, we type "alias findc Edit.Find *c* /wild /doc /markall":

image

 

You can double-check the alias assignment by typing "alias findc":

image