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

4

8

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.

Utile answered 17/8, 2010 at 15:40 Comment(0)
S
3

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

Sabbath answered 21/5, 2012 at 11:0 Comment(0)
C
2

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.

Cubitiere answered 13/9, 2010 at 19:18 Comment(2)
Yes I would definitely used such plugin. Even better to have such plugin for Word/Outlook too, I'm always pressing Ctrl+Space when typing in my e-mails and get really upset when words are not autocompleted :)Coeternity
I really can't mark this as an accepted answer. You didn't really help when I so think about it.Cupp
H
1

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.

Hourihan answered 31/1, 2018 at 1:11 Comment(0)
C
-1

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.sstatic.net/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.

Contractive answered 21/3, 2012 at 7:5 Comment(1)
please see my last EDIT. i am not looking for code completion, which is a must have in any IDE. i am looking for a simple way to have words auto-completed (by words I mean any words - not just method/field/property/type names. Even words in documentation or comments.)Cupp

© 2022 - 2024 — McMap. All rights reserved.