Visual Studio: Is there a way to do a “Search in Files” with a single shortcut?

I want to select an expression in the code and type Ctrl + Whatever so it has the same result as [Ctrl + Shift + F And pressing the "Find All" button]

EDIT: [Ctrl + Shift + F and pressing Enter] may be faster than a click, but I still want something more specific and faster

Note: I'm not interested in the "Find all links" label.

+4
source share
3 answers

You can use a macro. I wrote and changed it in VS2010:

Sub FindAllFiles() DTE.Find.FindWhat = DTE.ActiveDocument.Selection.ToString() DTE.Find.Target = vsFindTarget.vsFindTargetFiles DTE.Find.MatchCase = False DTE.Find.MatchWholeWord = False DTE.Find.MatchInHiddenText = True DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral DTE.Find.SearchPath = "Entire Solution" DTE.Find.SearchSubfolders = True DTE.Find.FilesOfType = "" DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResults1 DTE.Find.Action = vsFindAction.vsFindActionFindAll If (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound) Then Throw New System.Exception("vsFindResultNotFound") End If End Sub 

A macro can be set to a keyboard shortcut. See: http://msdn.microsoft.com/en-us/library/a0003t62(v=vs.80).aspx

+7
source

Not that I knew about it. Ctrl+Shift+F + ENTER ( ENTER instead of clicking Find All) is probably the closest. And if you're a touch typewriter, it's as fast as one shortcut.

Update

Now that the question has changed, my answer no longer makes sense. Go with the macro, as Fosco answered it.

+2
source

I have the same macro as @Fosco.

 ' Members for the search methods Private matchCase As Boolean = True Private searchWindowOne As Boolean = False Public Sub SearchFiles(ByVal fileTypes As String, ByVal searchPath As String) searchWindowOne = Not searchWindowOne DTE.Find.Target = vsFindTarget.vsFindTargetFiles DTE.Find.MatchCase = matchCase DTE.Find.MatchWholeWord = matchWholeWord matchCase = True matchWholeWord = True DTE.Find.MatchInHiddenText = True DTE.Find.Action = vsFindAction.vsFindActionFindAll DTE.Find.SearchPath = searchPath If (searchWindowOne) Then DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResults1 Else DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResults2 End If DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral DTE.Find.SearchSubfolders = True DTE.Find.FilesOfType = fileTypes DTE.Find.FindWhat = GetClipboard() If (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound) Then Throw New System.Exception("vsFindResultNotFound") End If End Sub Public Sub ChangeMatchCase() matchCase = False matchWholeWord = False End Sub 

This adds a bit more flexibility to the original approach. One of the good things is to search in both search boxes alternating . This means that your last two requests are always available. Of course, this cannot be used to directly map to a shortcut, but this allows you to do this:

 Sub SearchInProject() SearchFiles("*.*", "Current Project") End Sub Sub SearchInCode() SearchFiles("*.h;*.cpp", "Entire Solution") End Sub 

... and so on. Then they can be mapped to shortcuts and allowed a real search for a single key. As you may have noticed, I added a switch for the match case, which can be activated by the ChangeMatchCase macro for the next search. In my setup, I matched various searches with double keystrokes. So Ctrl+F,Ctrl+G searches around the world, Ctrl+F,Ctrl+D searches in the project, ... you get the point. I have similar mappings for all debugging materials, starting with Ctrl+D, Perhaps this has been the most important productivity increase in recent years.

0
source

Source: https://habr.com/ru/post/1339499/


All Articles