Click here to Skip to main content
15,881,089 members
Articles / Visual Studio
Alternative
Tip/Trick

Making F1 do something useful in Visual Studio

Rate me:
Please Sign up or sign in to vote.
4.90/5 (13 votes)
12 Feb 2011CPOL1 min read 12.5K   4   6
Thanks OriginalGriff! This is great and really helped me out. :-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...
Thanks OriginalGriff! This is great and really helped me out. :-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: 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:

VB
Sub GoogleSearchMSDN_FeelingLucky()
    GoogleSearchMSDN(True)
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
    Else
        '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
        searchFor.WordLeft()
        'Select to the end of the word
        searchFor.WordRight(True)
        text = Trim(searchFor.Text)
        'Move the cursor back to the original position
        searchFor.MoveToDisplayColumn(0, currentColumn)
    End If

    url = "http://www.google.com/search?q=MSDN+" + text
    If feelingLucky Then
        url += "&btnI=745"
    End If

    'Launch search in default browser
    System.Diagnostics.Process.Start(url)
End Sub


I hope this helps!

License

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


Written By
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! Pin
kupps15-Feb-11 15:44
kupps15-Feb-11 15:44 
GeneralReason for my vote of 5 Quicker and more reliable than Micro... Pin
BloodBaz14-Feb-11 2:31
BloodBaz14-Feb-11 2:31 
GeneralRe: I agree with you that Microsoft's help implementations are g... Pin
Keith.Badeau14-Feb-11 6:02
Keith.Badeau14-Feb-11 6:02 
GeneralHere's a quick hack to make it also work when the cursor is ... Pin
newmodel13-Feb-11 3:54
newmodel13-Feb-11 3:54 
GeneralRe: Good job newmodel. :) This edge case did run through my min... Pin
MattPenner15-Feb-11 6:44
MattPenner15-Feb-11 6:44 
GeneralReason for my vote of 5 Like it! That is a good enhancement ... Pin
OriginalGriff12-Feb-11 0:56
mveOriginalGriff12-Feb-11 0:56 

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

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