Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Eclipse-like WORD completion shortcut in VisualStudio 2010?

I have recently switched from Java development and Eclipse IDE to C# .NET and VisualStudio 2010. What I really miss is the Alt + / Eclipse shortcut for word completion. I am NOT speaking about IntelliSense auto completion stuff. I mean, I would like the text editor to finish writing words that already exist somewhere in the document but will not show up in IntelliSense, e.g. string literals.

In Notepad++ it is the Ctrl + Enter shortcut. In Eclipse it is the aforementioned Alt + /

Can VS2010 do the same? If not by default, can anyone point me to a decent VB macro that I could plug into my VS2010 to do this?

Thank you.

EDIT

Please mind there is a difference between CODE completion (i.e. what in most IDEs/clever editors is performed by Ctrl+Space) and simple WORD completion (what I am looking for). Word completion does not try to analyse the current context, or guess what type/method you might be after. All it does it tries to complete a work you started typing by looking around your cursor location and searching for similar words already occurring in the current document.

like image 778
Peter Perháč Avatar asked Aug 17 '10 15:08

Peter Perháč


3 Answers

I've created a simple VS macro:

Public Sub CompletePreviousWord()        

    Dim doc As EnvDTE.Document = DTE.ActiveDocument
    Dim selection As TextSelection = doc.Selection        

    ' word to left is what we want to find        
    selection.WordLeft(True, 1)
    Dim findWord As String = selection.Text

    ' get search text from the beginning of the document
    Dim ep As EditPoint = selection.ActivePoint.CreateEditPoint()
    ep.StartOfDocument()
    Dim searchText As String = ep.GetText(selection.ActivePoint)

    Dim match = Regex.Match(searchText, "[^a-zA-Z0-9_]?(" + findWord + "[a-zA-Z0-9_]*)", _
        RegexOptions.IgnoreCase Or RegexOptions.RightToLeft)        

    If match.Success Then
        ' replace the whole world - for case sensitive and to allow undo (by doing only one operation)            
        selection.Insert(match.Groups.Item(1).Value)
    Else            
        selection.WordRight(False, 1)
    End If

End Sub

Bounded it to alt-space and it does the trick for me.

Shlomi

like image 173
shlomiw Avatar answered Nov 15 '22 03:11

shlomiw


Can VS2010 do the same?

No by default.

If not by default, can anyone point me to a decent VB macro that I could plug into my VS2010 to do this?

Don't know any that exists. But this could be a nice project to do.

like image 44
Cédric Guillemette Avatar answered Nov 15 '22 05:11

Cédric Guillemette


In Visual Studio Code (VSC) there is an extension, "Another Word Completion" by getogrand. I know your question was regarding Visual Studio, but this may be of interest to others searching for this who wind up here.

Yup, hard to search for this since "code completion" term is more common.

like image 20
Josef.B Avatar answered Nov 15 '22 04:11

Josef.B