Visual Studio Tip: Customizing Search Output in Visual Studio

Sign in to queue

Description

When you do a Find in Files (CTRL+SHIFT+F), by default the output displays the file path which can fill up the results window. Did you know you can use a registry key to customize the output of your search?

Just create a string value in the registry called "Find result format" put it in HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\Find  (12.0 for VS 2013, 11.0 for VS2012, 10.0 for VS2010) then specify a value for your new registry string value of $f$e($l,$c):$t\r\n   This will display file name file extension (line number column number): line of code containing the string match and then inserts a carriage return.

The end result? Simpler search results (as long as you don't need the file path)

Embed

Download

Download this episode

The Discussion

  • User profile image
    Rob

    Awesome!
    Is there a way to only get a part of the path from the solution root folder?
    eg
    C:\Data\Projects\Projectname\Solutionname\Controllers\AccountController.cs
    becomes
    Controllers\AccountController.cs

  • User profile image
    JohnLudlow

    Cool. This really does need to go on the options dialog.

    One question (without trying it): does this mean you can't click on the path to open the file? Because if that still works, then it's the best thing ever. If not then I'd (personally) keep the need to scroll to the right if it means I can open the file.

  • User profile image
    dudumanbogd​anvlad

    Hi,

    Thank you. Very useful.

    Can we apply the same tip to "Find Symbol Results" - ctrl+k+r ? If so, can you please tell me what will be the correspondent Folder for the action "Find Symbol Results"?

     

    Thanks!

  • User profile image
    JonTims

    JohnLudlow, yes, you can still click to open the file.

    If you prefer a PowerShell script:

    Set-ItemProperty HKCU:\Software\Microsoft\VisualStudio\12.0\Find -Name 'Find result format' -Type String -Value '$f$e($l,$c):$t\r\n'

    -Jon Tims [MSFT]

     

  • User profile image
    JohnLudlow

    @JonTims: Sweet 

    Yeah the PowerShell script is better for copy-past-iness.

    And yes, @dudumanbogda​nvlad raises a good point that this would be useful in the Find Symbol / Find References windows

  • User profile image
    JohnLudlow

    BTW, I found this blog post which explains what the different specifiers mean:

    http://blogs.msdn.com/b/zainnab/archive/2010/01/03/customize-how-search-results-are-displayed-in-the-find-results-window.aspx

    This is the format I've started using:

    $f$e($l,$c):\t\t\t$s\r\n

    It's mostly the same, but I've added some tabs to separate the file name from the match, and used $s instead of $t because it seems to trim out any leading spaces from the match. This (IMHO) leads to a more regular list of matches which is less randomly spaced.

    Thanks for the tip

  • User profile image
    HockeyGeek​Girl

    You guys are off and running with this! Thanks for sharing the powershell script!

  • User profile image
    Ela

    Very helpful. Thank you for posting.

Add Your 2 Cents