Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Visual Studio 2015 Cookbook

You're reading from   Visual Studio 2015 Cookbook Over 50 new and improved recipes to put Visual Studio 2015 to work in your crucial development projects

Arrow left icon
Product type Paperback
Published in Aug 2016
Publisher Packt
ISBN-13 9781785887260
Length 368 pages
Edition 2nd Edition
Arrow right icon
Author (1):
Arrow left icon
Jeff Martin Jeff Martin
Author Profile Icon Jeff Martin
Jeff Martin
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Exploring Visual Studio 2015 2. Getting Started with Universal Windows Platform Apps FREE CHAPTER 3. Web Development 4. .NET Framework Development 5. Debugging Your .NET Application 6. Asynchrony in .NET 7. Unwrapping C++ Development 8. Working with Team Foundation Server 2015 9. Languages 10. Final Polish Index

Searching and navigating

Visual Studio provides many ways to make maneuvering through your code easier and more efficient. Let's take a look at a few of them.

Getting ready

To best see this in action, open a project that has multiple files available for editing. This can be the sample project or one of your own choice. Once it is open, simply open a couple of source files.

How to do it…

Pressing Ctrl + Tab provides easy access to a couple of different ways to navigate around Visual Studio. If Ctrl + Tab is pressed and immediately released, Visual Studio will alternate between the two most recent files that you have opened in the editor window, providing a quick way to move back and forth. If Ctrl + Tab is pressed and Tab is released, a pop-up window will appear. Continue to hold down Ctrl when it appears, and then arrow keys can be used to maneuver around the list of all active files and windows. To make a selection, either release Ctrl while highlighting the desired target, or while holding Ctrl, press Enter.

This is shown in the following example screenshot, where active files currently open in Visual Studio are shown in the right-hand side column, while open tool windows are shown in the left-hand side column:

How to do it…

There's more…

If you would rather use a keyboard mouse hybrid approach, the window Ctrl + Tab produces, and also supports, selection by mouse. Start in the same manner as done earlier in this recipe, holding down Ctrl + Tab to bring up the window. Release Tab while holding down the Ctrl key, and then use your mouse to left-click directly on the file you would like to switch to.

Quickly searching your code

Searching a project file to find specific strings of text is a common task regularly performed by developers. Visual Studio tries to make this easy by offering specific tools to find and replace text at various levels of your code base. Several options are available under Edit | Find and Replace, including Quick Find, Quick Replace, Find In Files, and Replace In Files.

Tip

The Incremental Search option (Ctrl + I) is a quick way to search within the file you are currently editing. When activated, a Find dialog box appears in your active editor window, allowing you to enter search terms.

The Quick Find (Ctrl + F) and Quick Replace (Ctrl + H) options share a common dialog box. Both provide the ability to search the current code block, the current project, all open documents, or the entire solution. If your search options include the currently open file, the vertical scroll bar will highlight any matches found. This provides quick visual feedback on the frequency of a search item:

Quickly searching your code

Another feature that Quick Find and Quick Replace share is the ability to set the following search options: match case, match whole word, and whether or not regular expressions can be used. The use of regular expressions allows for more complex queries to be used, allowing users to extract more detailed information from their searches.

The Find In Files (Ctrl + Shift + F) and Replace In Files (Ctrl + Shift + H) options provide a more advanced method of conducting searches across a code base. They expand on the functionality offered by the quick tools by allowing you to specify the file types that should be searched (for example, all HTML and JavaScript files), and provide the ability to display the results of an operation in a separate window.

Tip

When using Quick Find/Replace or Find/Replace in Files, Visual Studio will automatically prefill the word or character nearest your cursor into the search box.

Quickly searching your code

In the preceding example screenshot, a text string was used to search the entire solution using the specified file mask. The results were outputted to Find Results 1, which is a live window. This means that you can click on a line with a particular search result, and you will go directly to that file where the match was made. Notice that some of the details provided in the results include the line number and context of the value being searched for.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image