Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Making F1 do something useful in Visual Studio

By , 12 Feb 2011
Rate this:
Please Sign up or sign in to vote.
Thanks OriginalGriff! This is great and really helped me out. Big Grin | :-D
However, for my tastes I like to open the URL in the default browser (currently that's Chrome for me), which allows me to easily open up several tabs from the links or bookmark useful entries.
Also, the original F1 would search the Help based on what word the text cursor was on, whether it was selected or not. I liked the ease of that.
Last, but not least, as I was writing a blog post on this great tip I stated that 95% of the time my search term came up in the first result. Then it hit me. OMG | :OMG: If I think that what I want will be my first hit, why not just return Google's first result; the equivalent of hitting the older I'm Feeling Lucky button on Google's home page. So, I added a second subroutine that does exactly that. I set the key assignment for GoogleSearchMSDN_FeelingLucky to Shift+F1. Now, if I think a term is likely to return what I want in the first hit, like "msdn ActionResult" grabs the Microsoft MSDN page for the ActionResult class, then I use Shift+F1, otherwise I just use the standard F1 and get all the results.
So, I updated the code with these three features as follows:
Sub GoogleSearchMSDN_FeelingLucky()
End Sub
Sub GoogleSearchMSDN(Optional ByVal feelingLucky As Boolean = False)
    Dim url As String
    Dim text As String
    Dim searchFor As TextSelection = DTE.ActiveDocument.Selection()
    If Not searchFor.IsEmpty Then
        'Search value is selected.  Get the selected text.
        text = searchFor.Text
        'Text cursor is on the search value.
        'Store the current cursor location
        Dim currentColumn As Integer = searchFor.ActivePoint.DisplayColumn
        'Move to the beginning of the word
        'Select to the end of the word
        text = Trim(searchFor.Text)
        'Move the cursor back to the original position
        searchFor.MoveToDisplayColumn(0, currentColumn)
    End If
    url = "" + text
    If feelingLucky Then
        url += "&btnI=745"
    End If
    'Launch search in default browser
End Sub
I hope this helps!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Software Developer (Senior) Val Verde Unified School District
United States United States
Matt is an avid technologist and loves to see solutions he has helped create to make others’ work easier and more productive. While much of his work consists of software development, database design and website development he would say his job is largely designing and implementing solutions. As an integral member of the Riverside County of SELPA he was one of the leads in recently migrating 22 LEAs from one web-based IEP software to another. Matt’s ambition is to become a CTO within education.

Comments and Discussions

GeneralReason for my vote of 5 Very handy! Thanks a lot! Pinmemberkupps15-Feb-11 15:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140421.2 | Last Updated 13 Feb 2011
Article Copyright 2011 by MattPenner
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid