Customize how Find in Files results are displayed in the Find Results Window

Tips Search

Customize how Find in Files results are displayed in the Find Results Window

  • Comments 14

Keyboard:  CTRL + SHIFT + F
Menu:  Edit -> Find and Replace -> Find in Files
Command:  Edit.FindinFiles
Versions:  2008,2010
Published: 1/3/2010
Code:  vstipFind0002 

   

image

 

You can customize your Find in Files results to show what you want to see and how you want to see it.

Example:  You don't want to view the entire file path shown in the Find Results tool window.

So instead of this:

image

 

 

You want this:

image

 

No problem! :)

 

DANGER:  This involves hacking the Registry so use this tip at your own risk!

  1. Open up RegEdit
  2. Go to HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\Find
  3. Add a new string called Find result format with a value of $f$e($l,$c):$t\r\n

    image
  4. Hop into Visual Studio and run a Find in Files search (NOTE: You do not need to restart VS to see the changes made in the Registry, which is great for testing different string combos)

 

Here are valid values you can use in the string:

 

Files

$p      path                       

$f      filename               

$v      drive/unc share            

$d      dir                        

$n      name                       

$e      .ext                   

    

Location

$l      line                        

$c      col                        

$x      end col if on first line, else end of first line

$L      span end line

$C      span end col

Text

$0      matched text                

$t      text of first line

$s      summary of hit

$T      text of spanned lines

Char

\n      newline                   

\s      space                     

\t      tab                        

\\      slash                    

\$      $                 

  • Great tip, works beautifully in VS2008 !

    FYI, discovered this blog by searching for "visual studio" rss feeds on my.yahoo.com

  • The problem with this is that $d gives you the entire directory path (minus the device). So, your choice is between no directory information, or the entire dir path.

    What people with multiple projects would want is JUST THE LAST FOLDER of the directory path (the actual project folder). That is, the folder containing the file, as well as the file.

    So what is needed is a way to substring the $d value.

    I tried "$d[74]" (to start with the 74th character). Put it just appended "[74]" to the path string. Not terribly useful.

    Maybe some brilliant soul can figure out how to substring $d string. THEN this would really be useful!

  • Great tip Zain - will really come in handy when using VS on a laptop screen.

  • While it's changed slightly for 2010, this is plagiarized from saraford.net/.../customize-your-find-in-files-results-experience

  • Anonymous :)

    Actually it's taken directly from Sara's previous work.  Sara turned over the Tips to me and we are, in fact, writing a book together on the topics as well.  Just FYI.

    Z

  • Can you do the same for the "Bookmarks" window?  

    The "File Location" field can get very long, especially if you have your project/source in a sub-directory of your "My Documents".

    MSVS 2010 Pro

    Sorry if repeated

  • PATH ->$p\r\nRESULTS ->$f$e($l,$c):$t\r\n\r\n

  • DAC :)

    Sadly, no.  I am not aware of any other tool window that has this level of control.  

    Z

  • ca martin,

    cool!  I'll try it. :)

    Z

  • Is there any way to sort the results?

  • Aquaren :)

    Not that I am aware of short of putting them into Excel or some other tool.

    Z

  • This is a really nice feature, does there exist a possibility to output several findlines ?

    My usecase is to find some text with a regular expression which covers several lines of code, it would be nice to have all of them in the findresult

  • This feature seemed to disappear in VS 2012. Is there a known alternative?

  • Works fine in VS 2013 (which is 12.0 in the registry)

Page 1 of 1 (14 items)
Leave a Comment
  • Please add 2 and 1 and type the answer here:
  • Post