(surrounded by a space on each side), then the characters from the first group found (followed by
a semicolon in the C# example). If you aren’t familiar with regular expressions it may take some
time to get your head around it, but it is a very quick and easy way to perform an otherwise rather
mundane manual process.
Note that the regular expressions used in the Quick Find tool don’t have exactly
the same syntax as the standard regular expressions you might find in the .NET
Framework, with a few differences present between the two.
find and replace options
You can further configure the find-and-replace functionality with its own set of options in the
Tools . Options dialog. Found in the Environment group, the Find and Replace options enable you
to enable/disable displaying informational and warning messages, as well as to indicate whether the
Find what field should be automatically filled with the current selection in the editor window. There
is also an option to hide the Find dialog after performing a Quick Find or Quick Replace, which can
be handy if you typically look only for the first match.
78 .
chaPter 5 Find And replAce And help
find/rePlace in files
The Find in Files and Replace in Files commands enable you to broaden the search beyond the current
solution to whole folders and folder structures, and even to perform mass replacements on any matches
for the given criteria and filters. Additional options are available to you when using these commands,
and search results can be placed in one of two tool windows so you can easily navigate them.
This search tool is best suited when you need to do a simple text-based search/
replace across files that are not necessarily a part of your current solution.
find in files
The really powerful part of the search engine built into Visual Studio is found in the Find in Files
command. Rather than restrict yourself to files in the current solution, Find in Files gives you the
ability to search entire folders (along with all their subfolders), looking for files that contain
the search criteria.
The Find in Files dialog, shown in Figure 5-7, can be invoked via the menu command Edit . Find
and Replace . Find in Files. Alternatively, if you have the Quick Find dialog open, you can switch
over to Find in Files mode by clicking the small drop-down arrow next to Quick Find and choosing
Find in Files. You can also use the keyboard shortcut Ctrl+Shift+F to launch this dialog.
Most of the Quick Find options are still available to you, including wildcard and regular expressions
searching, but instead of choosing a scope from the project or solution, you use the Look In field to
specify where the search is to be performed. Either type the location you want to search or click the
ellipsis to display the Choose Search Folders dialog, shown in Figure 5-8.
fiGure 5-7 fiGure 5-8
find/replace in files .
79
You can navigate through the entire filesystem, including networked drives, and add the
folders you want to the search scope. This enables you to add disparate folder hierarchies to
the one single search. Start by using the Available Folders list on the left to select the folder(s)
that you would like to search. Add them to the Selected Folders list by clicking the right arrow.
Within this list you can adjust the search order using the up and down arrows. Once you have
added folders to the search, you can simply click OK to return a semicolon-delimited list of
folders. If you want to save this set of folders for future use you can enter a name into the Folder
Set drop-down and click Apply.
The process of saving search folders is less than intuitive, but if you think of the
Apply button as more of a Save button then you can make sense of this dialog.
find dialog options
The options for the Find in Files dialog are similar to those for the Quick Find dialog. Because the
search is being performed on files that are not necessarily open within the IDE or are even code files,
the Search Up option is therefore not present. There is an additional filter that can be used to select
only specific file types to search in.
The Look at these file types drop-down list contains several extension sets, each associated with a
particular language, making it easy to search for code in Visual Basic, C#, J#, and other languages.
You can type in your own extensions too, so if you’re working in a non-Microsoft language, or just
want to use the Find in Files feature for non-development purposes, you can still limit the search
results to those that correspond to the file types you want.
In addition to the Find options are confi guration settings for how the results will be displayed. For
searching, you can choose one of two results windows, which enables you to perform a subsequent
search without losing your initial action. The results can be quite lengthy if you show the full output
of the search, but if you ’ re interested only in fi nding out which fi les contain the information you ’ re
looking for, check the Display Filenames Only option and the results window will be populated with
only one line per fi le.
results window
When you perform a Find in Files action, results are displayed in one of two Find Results windows.
These appear as open tool windows docked to the bottom of the IDE workspace. For each line that
contains the search criteria, the results window displays a full line of information, containing the
filename and path, the line number that contained the match, and the actual line of text itself, so
you can instantly see the context (see Figure 5-9).
80 .
chaPter 5 Find And replAce And help
fiGure 5-9
Along the edge of each results window is a small toolbar, as shown in
Figure 5-10 (left), for navigation within the results themselves. These
commands are also accessible through a context menu, as shown in
Figure 5-10 (right).
Simply double-click a specific match to navigate to that line
fiGure 5-10
of code.
replace in files
Although it’s useful to search a large number of files and find a
number of matches to your search criteria, even better is the
Replace in Files action. Accessed via the keyboard shortcut
Ctrl+Shift+H or the drop-down arrow next to Quick Replace,
Replace in Files performs in much the same way as Find in Files,
with all the same options.
The main difference is that you can enable an additional
Results option when you’re replacing files. When you’re
performing a mass replacement action like this, it can be
handy to have a final confirmation before committing changes.
To have this sanity check available to you, select the Keep Modified
Files Open After Replace All checkbox (shown at the bottom of
Figure 5 - 11).
Note that this feature works only when you’re using Replace All; if
you just click Replace, Visual Studio will open the file containing the
next match and leave the file open in the IDE anyway.
fiGure 5-11
Important: If you leave this option unchecked and perform a mass replacement
on a large number of files, they will be changed permanently without your
having any recourse to an undo action. Be very sure that you know what
you’ re doing.
Whether or not you have this option checked, after performing a Replace All action, Visual Studio
reports back to you how many changes were made. If you don ’ t want to see this dialog box, you
have an option to hide the dialog with future searches.
find syMbol
The Find Symbol search tool enables you to search for a class, method, property, or other types of symbols.
Whereas the standard Quick Find function is essentially a plaintext search across your selected scope
(current document, current project, and so on), Find Symbol is limited to searching only for symbols.
You can invoke the Find Symbol dialog by the keyboard shortcut Alt+F12 or the menu command
Edit . Find and Replace . Find Symbol. Alternatively, you can switch the normal Find and Replace
dialog over to Find Symbol by clicking the drop - down arrow next to
Quick Find or Find in Files.
The Find Symbol dialog (see Figure 5 - 12) has slightly different options
from the dialogs for the other Find actions. Rather than having its
scope based on a current document or solution like Quick Find, or
on the fi lesystem like Find in Files, Find Symbol can search through
your whole solution, a full component list, or even the entire .NET
Framework. In addition, you can include any references added to the
solution as part of the scope. To create your own set of components in
which to search, click the ellipsis next to the Look in fi eld and browse
through and select the .NET and COM components registered in the
system, or browse to fi les or projects.
After you click Find All, the search results are compiled and presented in a special tool window
entitled Find Symbol Results. By default, this window shares space with the Find Results windows
at the bottom of the IDE, and displays each result with any references to the particular object or
component. This is extremely handy when you ’ re trying to determine where and how a particular
object is used or referenced from within your project.
fiGure 5 - 12
The Find options are also simplifi ed. You can search only for whole words,
substrings (the default option), or prefi xes.
This search tool is best suited for when you need to search for all instances of
a symbol and retrieve a list of all matches within the selected scope so you can
easily navigate to a number of the results. By limiting the search scope to only
symbols, you aren ’ t searching extraneous text such as comments, code within
methods, and so on. The search is also not limited to just your code but can
also search the .NET Framework and referenced assemblies.
find symbol . 81
82 .
chaPter 5 Find And replAce And help
naViGate to
Navigate To is a powerful new search tool in Visual Studio 2010, providing an alternative to the
standard find functions when searching for symbols. Like Find Symbol, you are limited to only
searching for symbols; a number of differences between this and how Find Symbol operates can
make this more useful.
As opposed to Find Symbol, Navigate To displays live results as you type the search text. The more
of the search text you type, the more the results are narrowed down. Double-clicking one of the
results closes the dialog and navigates to that result.
One of the most unique features of the Navigate To dialog, however, is in how it searches. Say you
are looking for a class named ProductSummary. In this search tool, spaces are essentially AND
operators, so typing prod sum as the search text (that is, searching for prod and sum in the same
symbol name) returns the ProductSummary class as a result, as would typing in sum prod.
The other unique search capability that it
has is its camel case searching. To find the
ProductSummary class you can simply search
for PS (the capitals in its name) to return it
as a result (as shown in Figure 5-13) — a
very powerful feature found only in this
search tool.
If you enter the text to search for in
lowercase, the matching will be non-casespecific.
However, if you enter an uppercase
character as a part of the search text, the
search will become case-specific.
The shortcut to open the Navigate To dialog is Ctrl+, (comma).
fiGure 5-13
This search tool is best suited for when you need to search for and navigate to a
single instance of a symbol, with the benefits of “live” results as you type and its
partial/camel case search capabilities.
increMental search
If you’re looking for something in the current code window and don’t want to bring up a
dialog, the Incremental Search function might be what you need. Invoked by either the
Edit . Advanced . Incremental Search menu command or the keyboard shortcut Ctrl+I,
Incremental Search locates the next match based on a plaintext search of what you type. To
search up the document instead of down use Ctrl+Shift+I.
Immediately after invoking Incremental Search, simply begin typing the text you need to find. The
mouse pointer will change to a set of binoculars and a down arrow. As you type each character,
the editor will move to the next match for the text you entered. For example, typing f would fi nd the
fi rst word containing an f — such as offer . Typing an o would then move the cursor to the fi rst word
containing fo — such as form ; and so on.
If you enter the text to search for in lowercase, the matching will be non - case - specifi c. However, if
you enter an uppercase character as a part of the search text, the search will become case - specifi c.
accessinG helP
You are exposed to a wide range of technologies as a developer. Not only do they evolve at a rapid
pace, but you are constantly being bombarded with additional new technologies which you must
get up to speed on quickly. It ’ s impossible to know everything about these technologies, and being
a developer involves constantly learning. Often, knowing how to fi nd information on using these
technologies is as important a skill as being able to actually implement them. Luckily, there are a
multitude of information sources on these technologies from which you can draw on. The inclusion
of IntelliSense into IDEs over a decade ago was one of the most useful tools for helping developers
write code, but it ’ s rarely a substitute for a full blown help system that provides all the ins and outs
of a technology. Visual Studio ’ s help system provides this support for developers.
The easiest way to get help for Visual Studio 2010 is to use the same method you would use for
almost every Windows application ever created — press the F1 key, the universal shortcut key for
help. Visual Studio 2010 has a brand new help system which uses Microsoft Help 3. Rather than
using a special “ shell ” to host the help and enable you to navigate around and search it, the help
system now runs in a browser window. To support some of the more complex features of the
help system such as the search functionality (when using the offl ine help), there is now a help