.NET Tools
Essential productivity kit for .NET and game developers
Finding Text More Quickly with Go to Text in ReSharper
In ReSharper, you can use Ctrl+T to Search Everywhere. And with everywhere, we do mean everywhere! Did you know ReSharper also indexes and searches in textual content?
I’ll use the Carter framework as an example solution in this blog post. When searching for DocumentTitle
, you can see that ReSharper finds relevant symbols (2 properties in this case), and also textual occurrences in appsettings.json
and throughout the codebase.
Go to Text helps you navigate to text in source and textual files easier and faster than using Visual Studio’s built-in Find in Files. Let’s look at it in more detail.
How does Go to Text work?
If you want to search a solution for text, such as error messages shown to the user, configuration keys, or specific comments you know exist, Go to Text can help. It lets you find text, whether the results are in source files, configuration, XML, JSON, or elsewhere.
When ReSharper indexes your solution, it tracks file names, classes, properties, methods, and other relevant symbols. ReSharper indexes raw text to make searches incredibly fast!
Fast searches allow us to include the results in Search Everywhere. ReSharper shows textual occurrences that match your query at the end of the results list, after matching types, symbols, and files.
If you intend to search for text only, you can press Ctrl+T 3 times (or use the ReSharper | Navigate | Go to Text menu) to trigger Go to Text directly.
By default, Go to Text searches in all source files and other textual files. If you want to exclude files and folders, you can do so in the ReSharper options under Environment | Search & Navigation, and add them to the Elements to skip collection.
Fuzzy search
Go to Text searches for exact text matches in your solution. With ReSharper 2020.3 EAP, we’ve added fuzzy search as well.
With fuzzy search, Go to Text takes into account various typos and missing words. Press Ctrl+T 3 times, and search for something that is slightly off. Fuzzy search results are displayed in a separate section of the result set.
You can get more creative with fuzzy searches. Since Go to Text searches all text, you can also search source code with it – even if your search is not an exact match.
An advantage is that fuzzy search can also help you find error strings, even if they contain format specifiers…
…or use string interpolation.
Note that if you want to disable fuzzy search, you can do so in the settings (ReSharper | Options | Environment | Search & Navigation). If you have any feedback on fuzzy search let us know in the comments!
Search for selection & repeat previous searches
Many of us know the copy/paste shortcuts pretty well. Text that is copied to the clipboard will appear in the search field, so you can use that precious Ctrl+C/Ctrl+V combination. However, each of us has a finite number of keys we can type!
You can save these two keystrokes by selecting some text or code, and then use the Go to Text shortcut to start searching immediately.
Very often, you’ll find yourself repeatedly searching for text to find the exact result. ReSharper will remember your last search, allowing you to immediately repeat it.
When you clear the search box, the last 10 searches are shown. You can use the keyboard up and down arrows to select any previous search and run it again.
Filtering results
For some queries, you may get back a large number of results. A massive result can be overwhelming, but maybe you know which file type your result is in, or you may find the results in the current project or the current folder.
By appending a search filter to your query, you can search for text in a particular extension by using the /ext
filter:
The following filters are supported:
/ext:
limits the search to files with specific extension(s), for example/ext:cs
or/ext:xml;json
;/fm:
limits the search to files matching a specific mask, for example,/fm:I*.cs
;/cp
limits the search to files in the current project;/.
limits the search to files in the current folder.
Find results tool window
For large projects, filtering can help find the expected result in one go. But what if you want to look through many results?
Like with other navigation features in ReSharper, you can use the Show in Find Results (+ on the numeric keypad or Shift+Enter) to show results in a separate tool window.
By default, search results are grouped by project structure. It may also group results differently or export results.
One of my favorite methods to help narrow search results in the Find Results tool window is to Filter Usages. The feature helps refine search results by where/how the results are used. For example, you can select to only show results that are found in unit tests, or only those in XMLDoc.
Give the latest ReSharper 2020.3 EAP with fuzzy search a try! Let us know what you think!