12

Because of all the sub-directories my code typically lives in, whenever I do a Find In File for something, the code gets run off the screen because the results window has wasted so much valuable real estate by repeating the long file path for every object in my solution. More often than not, they are in the same parent directory, or I don't really care where there from.

Is there an option to shorten the path name to perhaps just the file?

Unnecessarily long

Also, the Display File Names Only option in the Find in Files dialog does not do this, it only omits the code from the result.

Find in Files Dialog

KyleMit
  • 30,350
  • 66
  • 462
  • 664

3 Answers3

10

You can change the VS search result formatting by changing the registry.

According to the article Customize how Find in Files results are displayed in the Find Results Window:

  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

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

Further, here's the syntax to use if you'd like to customize the string further:

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
  • \$ - $
KyleMit
  • 30,350
  • 66
  • 462
  • 664
Carra
  • 17,808
  • 7
  • 62
  • 75
  • Annoyingly, my registry has two keys for Visual Studio 15 -- both are 15.0_8CharacterHexString. Seems the only way to tell which one is for my VS install is to experiment? – William Jockusch Aug 07 '17 at 16:01
  • @WilliamJockusch Maybe they both are. One could be for "show file name only" and the other could be for the full output? – mbomb007 Nov 15 '17 at 20:06
  • 3
    Anyone know if they moved these settings in VS 2017, i can't fnd any registry keys. Maybe there is some settings files or something somewhere nowadays? – Olaj Mar 21 '18 at 09:11
  • 2
    @Olaj - follow [Stephen Rauch's answer](https://stackoverflow.com/a/49723961/1057791) - I can confirm that it worked well for me. – BornToCode Feb 20 '19 at 21:59
5

Things are different on Visual Studio 2017. You won't find the registry keys for Visual Studio 2017 anymore as Visual Studio 2017 now stores registry keys in a private binary file under %VsAppDataFolder%\privateregistry.bin.

However, according to this link, there is still a way to find and modify registry keys for Visual Studio 2017.

  • Close Visual Studio 2017
  • Open regedit
  • Select HKEY_LOCAL_MACHINE from the left bar
  • Select File > Load Hive...
  • Load the privateregistry.bin file from %localappdata%\Microsoft\VisualStudio\15.0_[instanceid]{RootSuffix}\privateregistry.bin. The RootSuffix for a normal VS installation will be blank. This is mostly used for the experimental instance
  • Name the key whatever you want (e.g. "VS2017") when prompted
  • From there, you should be able to view the entries just like any normal registry.
  • Customise it according to accepted answer's suggestions.
  • Important! Once you're finished, you need to make sure that you "Unload" the private registry, by selecting the "root" key ("VS2017" in this example) and selecting File > Unload Hive . If you don't do this, VS won't be able to read the privateregistry.bin file when it runs, causing major problems.

Update: It also works on Visual Studio 2019 (version 16.0) too.

zagZzig
  • 136
  • 1
  • 9
  • After these steps my VS2017 doesn't start anymore. Unknown error is occurred. – Eugene Maksimov Jun 01 '18 at 07:31
  • sorry to hear that.It worked for me. Please double check if you had followed the procedure exactly. Maybe a typo or extra space? Hope you did a backup before modifying the registry. – zagZzig Jun 03 '18 at 05:03
  • 2
    I've provided a suggestion to Microsoft to make it possible. You can support it here: https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/34419535-shorten-file-paths-in-find-results-window – Eugene Maksimov Jun 04 '18 at 07:58
  • Just to confirm that I have followed this procedure again on a Windows 10 laptop. It worked for me. – zagZzig Jul 09 '18 at 06:05
  • @EugeneMaksimov Fwiw, I opened VS 2017 while the hive was still mounted in regedit and it errored out. Unmounting it (like I was supposed to ;^D) made things happy again. YMMV, always make a backup, 2¢, etc etc. – ruffin Jul 18 '18 at 17:07
  • Just to confirm that it works on Visual Studio 2019 as well. – zagZzig May 17 '19 at 02:10
  • @EugeneMaksimov your link is no longer valid. (at)zagzzig, im not getting this working on a new installation. I agree that microsoft should improve this,. or someone could perhaps make a plugin that would allow customization. – T.S Jun 19 '19 at 13:04
  • `From there, you should be able to view the entries just like any normal registry` - When navigating under the new key you loaded and named (e.g. "VS2017") which will be found under the HKEY_LOCAL_MACHINE folder on the left bar. – BornToCode Sep 20 '22 at 22:09
  • An alternate way to modify VS private registry keys can be found [here](https://stackoverflow.com/questions/43918053/how-to-change-the-find-result-format-in-visual-studio-2017) – BornToCode Sep 20 '22 at 22:46
  • Unfortunately, it didn't have any effect on VS 2022 even after I added the "Find result format" key to its private registry. – BornToCode Sep 20 '22 at 22:49
1

There is an option you can select "Find results table". Then you can do a Ctrl+ALL and copy the tab delimited results to a spreadsheet such as Excel. Then you can see only the code instead of file names.

enter image description here

live-love
  • 48,840
  • 22
  • 240
  • 204