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

1k views Asked by At

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.

4

There are 4 answers

0
shlomiw On

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

2
Cédric Guillemette On

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.

0
Josef.B On

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.

1
Ron Ryl On

VS2010 has that feature by default:

Shortcuts: "ALT + RIGHT ARROW" or "CTRL + SPACEBAR"

Toolbar button: (as I'm a new user, please open the screenshot picture manually at https://i.stack.imgur.com/OyiHY.png)

Relevant Command Object Name: Edit.CompleteWord (see: http://msdn.microsoft.com/en-us/library/xte2hh6a%28v=vs.71%29.aspx )

BTW, I'm using VS2010 professional.