I want to select an expression in code and type Ctrl+Wh开发者_如何学运维atever
so it has the same result as [ Ctrl+Shift+F AND Clicking on "Find All" ]EDIT : [Ctrl+Shift+F AND Hitting Enter] may be quicker than clicking but I still want something more specific and faster
Remark : I am NOT interested the Find All References shortcut.
You could use a macro. I recorded and modified one 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
The macro can be set to a keyboard shortcut. See: http://msdn.microsoft.com/en-us/library/a0003t62(v=vs.80).aspx
Not that I would be aware of it. Ctrl+Shift+F + ENTER
(ENTER instead of Clicking on "Find All") is probably the closest it comes. And if you are a touch typist it is as fast as a single shortcut.
Update
Now, that the question has changed my answer makes no sense anymore. Go with a macro like Fosco answered it.
I have a similar macro in use like @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
It adds a little more flexibility to the original approach. One of the good things is that is searches into both find windows alternating. That means your last two searches are always accessible. Of course this can't be used to be directly mapped to a shortcut but it allows to do this:
Sub SearchInProject()
SearchFiles("*.*", "Current Project")
End Sub
Sub SearchInCode()
SearchFiles("*.h;*.cpp", "Entire Solution")
End Sub
...and so on. These can then be mapped to shortcuts and allow real one key searching.
As you might have noticed I added a switch for match case that can be activated by the macro ChangeMatchCase
for the next search.
In my setting I mapped different searches to double keystrokes.
So Ctrl+F,Ctrl+G
searches globally, Ctrl+F,Ctrl+D
searches in the project, ... you get the point. I have similar mappings for all debug stuff starting with Ctrl+D,
.
This was maybe the single most important performance boost I had in the last years.
精彩评论