Modernizing Find in Files

Dante Gagne

Dante

Find in Files is one of the most commonly used features in Visual Studio. It’s also a feature that gets a substantial amount of feedback, and due to the age of the code, has been very costly to improve. Earlier this year, we decided to reimplement the feature from the ground up in order to realize significant performance and usability improvements.

We’ve released the new find in files experience in Visual Studio 2019 version 16.5 Preview 1 and we’re looking for feedback from the community. We expect this experience to be the one our developers will use and love in the future, so we want to make sure we’ve prioritized the right features. We still have more improvements coming that we’re not quite ready to talk about yet, but before we deprecate the old experience, we want to make sure the new version is meeting the needs of our users.

A screen capture of the new Find in Files dialog.

The new experience is available by searching for “Find in Files” or “Replace in Files” in Visual Studio search (Ctrl+Q by default). You can also get to these commands with Ctrl+Shift+F and Ctrl+Shift+H respectively. The new experience is pictured above and should be easily recognized by the more modern look and consistent color theming.

If you’re not seeing the new version, you can search for “Preview Features” in Visual Studio search (Again, Ctrl+Q by default). On that page, make sure “Use previous Find in Files” is unchecked. Conversely, if you’re having problems with the new experience, you can toggle this option to enable the old one. If you do find that you need the old Find in Files experience, we’d love to hear why. Please feel free to supply any feedback you might have over in Developer Community.

Performance

We took the previous implementation of Find in Files and reimplemented it completely in managed C#. This allows us to avoid unnecessary interop calls and gives us much more room for improving the experience. The memory consumption is smaller, and our performance is much faster.

In our internal testing on directories containing 100k+ files, we saw searches that took over 4 minutes with the old implementation be done in 26 seconds. The biggest gains are in searches that use regular expressions, but searches without regular expressions generally cut the search time in half.

Specifying Paths

Using the new experience should feel comfortable for most folks since we’ve gone with an experience that matches many other common find experiences. There are a few nuances that are worth calling out.

A screen capture of the Find in Files dialog that is cropped to only show the Look in and File types fields along with the options to include miscellaneous and external items.

The “Look in” box has a new option, “Current Directory”, which will search the folder that contains the currently open document. When searching a solution, there are checkboxes to include miscellaneous files (files that you’ve opened but aren’t part of the solution) as well as external items (files like “windows.h” that you might reference but aren’t part of the solution).

The three dots button next to the “Look in” box work like any other browse option to specify a directory to look in, but if you’ve already specified a directory, this button will append the new directory instead of replacing. For instance, if your “Look in” value was “.\Code”, you could click the three buttons and navigate to a folder named “Shared Code”. The “Look in” would now show “.\Code;.\Shared Code” and when the Find command is executed, it will search both of those folders.

The File types folder now also can exclude files. Any path or file type prefixed with the “!” character will be excluded from the search. For instance, you can add “!*\node_modules\*” to the file types list to exclude any files in a node_modules folder.

Multiple Searches

One of the more frequent requests we’ve gotten is the ability to keep the results from one search while doing other searches. This makes it easy to compare results and see them side-by-side. This feature has been in Visual Studio for a while, and the new experience still supports it.

In the screenshot above, the Keep Results button has been enabled. Now, when a new search is executed, the results will be shown in a new tab. The screenshot above shows three searches that have already completed. Currently, this feature supports up to five searches. If you’ve already got five search results showing, the next search will reuse the oldest search result tab.

The Keep Results button is available for Find in Files as well as the Find All References feature.

Regular Expression Builder

A screen capture of the Find in Files dialog with a regular expression being used.

With Visual Studio 2019 version 16.5 preview 2, the Regular Expression builder will be available. The “Use regular expressions” checkbox will enable you to specify a regular expression as a pattern for a match. Checking this box with Visual Studio 2019 version 16.5 preview 2 (or later) will also bring up the Regular Expression builder, which is useful for creating regular expressions. Regular expressions can allow searches for strings that span multiple lines. For instance, the expression “.*Hello.*\r\n.*World.*” will match any occurrence of the string “Hello” that has an occurrence of the string “World” anywhere on the next line.

When the “Use regular expressions” checkbox is checked, the regular expression builder will appear next to the Find field. Clicking this will give some examples for building regular expressions as well as a link to the documentation.

What’s Next

Now that the Find in Files experience has been reimplemented to use the newer patterns of Visual Studio, we’re going to be able to provide more of the features we get asked for. We’d love to hear your experiences with the new dialog. We’re always watching Developer Community, and we’ve got a survey specifically for collecting feedback on the new experience that you can answer here. We know there are features that aren’t available today and your feedback is how we’ll prioritize the rest of the features. If you’re running into problems or you think the new dialog isn’t working correctly, please send us feedback with the Give Feedback button in Visual Studio.

35 comments

Comments are closed.

  • Avatar
    Ziv CaspiMicrosoft logo

    The terms “miscellaneous files” and “external files” make sense when you read a blog, but I’d bet that very few developers (other than the PM who spec’ed the feature of course) will have an easy time realizing what they mean. Why not choose a simpler text, such as “Include files not in solution” or something? It’s not like the dialog box lacks horizontal space.

  • Roberto Mencia
    Roberto Mencia

    It would be great to have a checkbox in the results tab to track changes and auto update results (line numbers) while the code is being updated.

    I use the find to look for parts of code that I need to update or delete, but when the code is updated, then the line numbers change and when I click on references the line that it takes me to has changed and I need to re-run the query.

  • Avatar
    SuperCocoLoco .

    This is the same as the destroyed “New Project” dialog or the destroyed “Start Page”?
    Is now the turn to destroy the “Find Files” dialog?

    Why modernizing means ugly for Microsoft? The new project dialog is flat, plain and ugly, instead of the actual grayed and degrade 3d buttons, text boxes, checkboxes, etc. Looks ugly like all Windows 10.

  • Avatar
    Keith Patrick

    Biggest problem with Find in Files – that VS constantly positions the caret in the Find Results to the end of the list. So let’s say I search for “foreach”, and within 10 hits, I (quickly) see the file I’m after, so I try to click the item. Except, VS has scrolled the text down 50+ lines as another back of search results comes in. I lump this into a general “VS keeps changing user focus without corresponding user inputs” problem area – leave focus alone! I’m quite often doing something as I wait for VS to finish some other (async) task I asked it to do, but when VS starts moving things around simultaneously, it makes for a VERY frustrating experience (the toolbar mess is another area where this general VS behavior is a headache…it’s like the VS team only has a single usage scenario – 1. User clicks button, 2. User waits for task to finish + additional time to account for a usual lack of “I’m finished” cue, 3. Once UI task(s) finishes, user *then* goes to finish any other tasks, totally happy that s/he has to work serially in 2019.
    Another one would have to be the inconsisteny wrt the initial field that VS sets user input focus to…Find puts user focus in “Find what”, while Replace starts you in “Replace with”. NOTE: “Find what” is not always populated with the correct text, since it likes to insert highlighted text there automatically, so my frustration lies in the inconsistency – I’d rather the two different functions flow almost identically, given that they share a UI.

  • Avatar
    Ben Raubenolt

    I hope this new find will allow me to easily search all file folders under the tree I’m viewing in Solution Explorer. If I click “Scope to This” in the solution explorer to limit my view of the tree, search should easily allow me search just those files. This is particularly important with web projects that aren’t part of a solution.