Inside Microsoft® Visual Studio® .NET 2003 [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Inside Microsoft® Visual Studio® .NET 2003 [Electronic resources] - نسخه متنی

Brian Johnson

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید










Using the Command Window


If you've used a modal editor such as Vim (Vi improved) for a number of years and are used to typing editor commands in at a command line, the Command Window in Visual Studio .NET will come as a welcome surprise. I've already referred to using the Visual Studio .NET Command Window a number of times (in both Chapter 1 and Chapter 2), but it's worth considering the various ways you can use this tool in your everyday work.

If you've installed and played with the Keybindings Table add-in, you'll find that more than 1100 commands are available in the IDE. Of those commands, nearly 400 are bound to keyboard shortcuts by default. That leaves a huge number of commands that are available only through menus, toolbars, or the Command Window.

The Command Window in Visual Studio .NET supports two modes of operation. In Command Mode, the Command Window runs named commands. In Immediate Mode, the Command Window evaluates expressions related to the code you're working with. You can toggle between Command Mode and Immediate Mode using a couple of commands. Typing immed will put the Command Window into Immediate Mode. You can switch back to Command Mode by typing >cmd. In fact, you can do some expression evaluation in Command Mode while debugging by prefixing your command with a ? (question mark), as shown here:


>? i
4
>? i = 7
7
>? i + i
14

Conversely, you can easily enter a command while you're working in Immediate Mode by prefixing your command with a > (greater than) character:


i
7
i + i
14
>Edit.Find i
>immed

You'll notice that as soon as you enter a completed command, the Command Window switches into Command Mode. You'll need to enter the immed command to get back to Immediate Mode. Certain commands, such as Edit.Find, open a dialog box and return you to Immediate Mode.

Tip

You can clear the Command Window by entering the cls command. You can do this from either Command Mode or Immediate Mode; the Command Window will be returned to the mode that it was in when you entered this command.

As you've probably noticed by now, the named commands in Visual Studio .NET generally map to menu commands in the IDE. So if you want to use a named command from the Command Window, all you usually need to do is to type the name of the menu containing the command and then the dot operator and the name of the command. For example, if you want to search using the Command Window, you first bring the window to the front by pressing Ctrl+Alt+A. To open the Find dialog box, you enter Edit.Find into the Command Window. You'll notice that some commands, such as the Edit.Find command, can take arguments. This means you can search from the Command Window without having to deal with a dialog box. Whether or not you find this approach better is a matter of taste. Now let's take a look at an idea that we introduced a little earlier in the chapter, aliasing, and look at how we can use that feature to make our work in the Command Window a little easier.

We'll use the Edit.Find command as an example here. For this command to be really useful, you need to be able to quickly type the command and the search parameters. Entering Edit.Find takes a little more effort than you would normally want to expend on a command that you can already perform efficiently in a number of different ways. So let's map this command for a reason other than convenience. Let's say you're used to working in the Vi editor and you find yourself wanting to type \ (backslash) to search for items in the Text Editor. You can alias the backslash character to Edit.Find using the following command sequence:


>alias \ Edit.Find

To use the new alias, you type your command just as if you were using the actual named command. The following shows using the new \ alias to search in the Text Editor for a couple of terms:


>\ main|args /regex

This implementation of the \ search character isn't perfect. You need to type a space between the character and the term or expression you're searching for. This feature does the job, though, and it makes converting to the new editor just a little easier.

You'll probably find that aliasing commands is most useful for macros that you've written. The paths to these macros can get pretty long, and an alias can save you a lot of work. We'll talk about macros and how to employ them in the IDE in Chapter 4.

There are two ways to get to a command prompt in Visual Studio .NET. The way that we've described in the book so far is to open the Command Window using the Ctrl+Alt+A shortcut. You can also type commands into the Find combo box on the Standard toolbar by pressing Ctrl+D (Edit.GoToFindCombo). Normally, typing text in the Find combo box simply gives you a quick way to search the currently open document for a term or phrase. When you type a > (greater than) character into the box, the box changes to one capable of taking commands. You can then type named commands in the box that you would usually type in the Command Window. Because both the Command Window and the Find combo box support IntelliSense, you can simply type a named command to see all the possible completions for the command. You can see the list of completions in Figure 3-19.


Figure 3-19. Command completion in the Find combo box




/ 118