Home > 2012, Visual Studio > Visual Studio 2012: Find in Files Feature

Visual Studio 2012: Find in Files Feature


Introduction

This is the second post of a 30 post series that covers futures in Visual Studio 2012 and TFS 2012. Posts will range from beginner level to advance level.

You may want to read the post about the Quick Find feature first.

Expertise Level

Beginner

Find in Files

The Quick Find would be a slow option to find certain text if the matched text is repeated across too many files. In such a scenario, you are better off leveraging the Find in Files feature. The Find in files dialog comes equipped with a regular expression builder to assist in building a regular expression string.

There are three methods to launch the Find in Files dialog

1. Ctrl + Shift + F keyboard shortcut

2. EDIT —>Find and Replace —> Find in Files

image

3. From the Quick Find dialog, expand the search history and click on Find In Files … link

image

The Find and Replace Dialog looks as follows

image

1. Two tabs, Find in Files and Replace in Files, to toggle between the find and replace

2. The text or expression to find

3. Look in: the scope that Visual Studio should use to search. Clicking on the ellipsis button image allows you to add folders to the scope. This feature should be explained later on in this post

4. The checkboxes has been explained in the Quick Find feature post. Notice when the “Use Regular Expressions is checked, the Expression builder button  image is enabled. The Loo at these file types drop down allows you to specify the file extensions of the files to be searched where blank is the same as *.*

5. List results in: specifies whether the search results displayed in “Find Results 1” or “Find Results 2” window

image

Display file names only: when unchecked, the Find Result window shows the name of the file, line number where a match exists and the line of text where the match is found

image

whereas when it is checked the Find Result window displays only the file name where the match is found

image

6. Find Previous and Find Next highlights the previous and next match respectively

7. Find All, find all matches for the search criteria and displays them in either the Find Result 1 or Find Result 2 Window

8. Bookmarks the lines of code where matches are found. It is like adding them to favorites to look at them later on

Choose Search folders

Clicking on the ellipsis button next to the Lookin combobox launches the following dialog

image

The dialog allows you select one or more folder to be added to the search scope in the find in files feature. By default the C: drive will be displayed in the number 1 list. Double click on the C:\ drive to dig down and list the folders within it. I kept opening folders until I got to the C:\Users\Ahmed\ directory and selected the My Document folder and then press the > button at 5. Alternatively, you can type C:\Users\Ahmed\ on the Available folders dropdown (4) and press enter then press the > button to move the folder to the Selected folders list

image

While I am in the the Ahmed folder, I am also selecting the Downloads folder

image

I want to save those folders as folder set to use it later if I wanted to. To do so, I named the folder set as Docs_Downloads and then clicked the Apply button. Then click the OK button to go back to the Find in Files dialog

image

Notice that the folder set is selected in the Look in drop down and the Include sub-folders is available (enabled).

I then tried to find the text “status” in the Docs_Downloads folder set and I got a list of matches in the files in both My Documents and Download folders.

While the search is running, you may want to stop it. To do so, press the Ctrl + Shift + F combination and then click the Stop Find button

image

Advertisements
  1. January 11, 2013 at 4:34 am

    Very thorough write-up! You might be interested in http://entrian.com/source-search/ – when Find In Files is too slow for a large solution, Entrian Source Search is instant (because it builds an index of your source code). (Disclosure: I’m the author.)

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: