41

In Visual Studio 2010 and earlier, the Find in Files feature remembered your selection for the "Look in" option.

In 2012, the option sometimes gets reset to "Current Document", making it only search in a single file. This can be annoying, particularly when you don't notice it's done it.

Is there any way I can force this setting to stick with what I want it to be (generally "Entire Solution")?

As an example of the problem, highlight a few lines of text in a source file and bring up the Find in Files box. It will have changed the "Look In" setting to "Selection". Close it, deselect the text and do Find in Files again. The setting will have silently reverted to "Current Document". Doing this in 2010 and earlier doesn't change the setting.

There's another description of the problem here.

James Sutherland
  • 3,793
  • 2
  • 27
  • 24
  • Just tried here in VS 2012 and Find in Files doesn't reset to Current Document. Have you tried resetting all settings? – Francis Nepomuceno Nov 13 '12 at 23:38
  • Tried on a clean install and still get the same problem. – James Sutherland Nov 20 '12 at 10:33
  • My issue is with SQL files. Add a SQL file to your solution and then hit CTRL+F - it launches the "Find In Files" dialog. Then when you change it to "Current Document" it remembers the setting making a very annoying user experience. So, it seems the inline/new VS2012 doesn't work with certain file-types. Can this be fixed? – PeterX Dec 18 '12 at 00:35
  • 4
    Gods below, I HATE this idiotic anti-feature! Worse than "current document" is the insistence on "current window" - which it switches to every time I finish a search. I've tried all of the given answers - all fail. Launching find/find-in-files when the cursor is in the search results window (which VS stupidly puts it into after every search) changes the "Look in:" to be "Current Window". Every freaking time. !@#$!@#$!@#$ – Mordachai Dec 30 '14 at 17:52
  • 2
    This is the most maddening UI decision in Visual Studio. It should do the SAME thing every time I hit Ctrl-Shift-F. Instead, I have to reset and fill out the form over and over every time, since it ALWAYS guesses wrong. If there are multiple options (e.g. search-in-file, search-in-project, search-in-solution, search-in-selection), there should be different shortcuts for each. – mikebridge Mar 16 '15 at 16:06

4 Answers4

6

I find that its intermittent (but more often that not) and that its a potential bug. For me it resets to "All Open Documents" which could be far more disastrous.

Do you have any plugins installed as I was thinking of raising this as an issue with vs if its not a 3rd party tool affecting it?

I have the following installed:

  • Resharper 7.1
  • Teamcity
  • Ankh
  • Entity Framework Power Tools Beta 2
  • Ghost Doc
  • Microsoft Web Developer Tools
  • NestIn
  • NuGet
  • Spell Chekcer
  • SQL Server Compact Toolbox
  • VS Extensions for Windows Library JavaScript

I guess we should rule out some of these first?

Anyone else find this who has no extensions installed?

Dewy
  • 153
  • 5
6

Try if the SmartFind extension helps in your case. I wrote it because I had a similar problem.

http://visualstudiogallery.msdn.microsoft.com/015611c4-b357-4672-8977-f3ec92f0b808

Source is here: https://github.com/laktak/vs-smartfind

laktak
  • 57,064
  • 17
  • 134
  • 164
  • Sounds like what I need, but it didn't work for me, I'm using Visual Studio Professional 2012 Version 11.0.61030.00 Update 4 – Myster Dec 15 '14 at 00:44
  • @Myster you probably forgot to set the options. first select your preferred options (in find) the do tools/reset smartfind. – laktak Dec 15 '14 at 11:02
  • I definitely did that, several times :-] fortunately my VS2013 licence came through so I'm using that now, and it's fine. – Myster Dec 15 '14 at 23:11
  • This needs to be updated to prevent Visual Studio from switching to "All Open Documents" after running a "Replace All". Are you game to try that, @laktak? – Sean Kendle Feb 15 '17 at 20:23
  • @SeanKendle you say 'needs to be updated', do you mean for VS 2017? – laktak Feb 15 '17 at 20:48
  • No, I mean added functionality. Try this: Open Find in Files, set the dropdown to "Current Document", run a Replace All, watch the dropdown list. It switches to "All Open Documents" *every time*. It's a known bug in VS, and no one has bothered to fix it. I figured you're the one for the job, since you've gotten your hands dirty already. – Sean Kendle Feb 15 '17 at 21:42
  • I would pay $10 for an add-on that prevents that from happening. You have no idea how many times I've accidentally found and replaced things across all open documents. It's infuriating. – Sean Kendle Feb 15 '17 at 21:42
  • @SeanKendle you should use the find/replace dialog with smartfind (Ctrl+H) for that instead of find in files. – laktak Feb 15 '17 at 22:15
  • I just prefer the find in files dialog off to the side. I leave it open always. I remapped my ctrl+f and ctrl+h to that dialog instead of the "quick find/replace" dialog. Is there no way to just have that dialog *never* change the "find in" drop down list selection? – Sean Kendle Feb 16 '17 at 14:00
  • @SeanKendle SmartFind will reset to your defaults every time you open the dialog. So after ReplaceAll press ESC and then Ctrl+H. – laktak Feb 20 '17 at 08:07
  • Here's the thing, if I'm copy/pasting text from another file, and replacing a lot of variable names, I'm not exiting the search. So, I run one replace, then immediately change the names and run it again. Unbeknownst to me, the drop down has changed to "All Open Documents", and if I don't hurry up and CTRL+Z, I can end up with everything replaced in the other open file I'm copying from. Also, it switches after the replace, so sometimes I go to double check to see if I had "Current Document" selected, but it's already changed, so I don't know if I've replaced everything in all documents. – Sean Kendle Feb 20 '17 at 13:53
  • @SeanKendle VS (at least up to 2015) does not have an API for this - I'm using a workaround that probably wouldn't work with the dialog open. Maybe you are using the wrong tool for the job? You could add a shortcut to open the current document in Sublime/Atom (see http://stackoverflow.com/a/13462358/52817) and find/replace the text there. – laktak Feb 20 '17 at 20:35
  • I wish Microsoft would just change this "feature" to *never* change the drop down without the user changing it manually. I absolutely hate when software tries to be "smarter" than me. – Sean Kendle Feb 20 '17 at 20:47
  • @SeanKendle have you heard of Autohotkey (autohotkey.com)? You can probably get it to do what you want for you. – laktak Feb 22 '17 at 12:21
  • Thanks for the suggestions. I'll just be more careful with it. I've also found that "Replace All" doesn't change the ddl to "All Open Documents" if you set it to "Selection", so I might just select all to do any replacing within a file from now on. Let me know if you ever look into that or feel like you can fix it, and I'll keep the pressure on Microsoft to fix this in the stock program. Thanks for your smart search plugin, it's definitely helped a ton! – Sean Kendle Feb 22 '17 at 14:21
6

What worked for me is under keyboard customization i made it so Ctrl-Shift-F maps to Edit.SwitchtoFindInFiles instead of the default (Edit.FindInFiles). I did also install the SmartFind extension (mentioned above in this tread) but by itself it didn't seem to fix it. I'm not sure if it's the combination of the two that fixed it in my case. Also note that this applies to VS2012 so YMMV.

Andrei Pokrovsky
  • 3,590
  • 3
  • 26
  • 17
-1

I always use ctrl + f to search in document and ctrl + shift + f to search the entire solution.

Might not be an answer to your question, but it should solve your problem.

Eric
  • 245
  • 1
  • 9