8

我最近从 Java 开发和 Eclipse IDE 切换到 C# .NET 和 VisualStudio 2010。我真正怀念的是用于单词完成的Alt+ Eclipse 快捷方式。/我不是在谈论 IntelliSense 自动完成的东西。我的意思是,我希望文本编辑器完成编写文档中已经存在但不会出现在 IntelliSense 中的单词,例如字符串文字。

在 Notepad++ 中,它是Ctrl+Enter快捷方式。在 Eclipse 中是前面提到的Alt+/

VS2010 可以做同样的事情吗?如果不是默认情况下,谁能指出我可以插入到我的 VS2010 中的体面的 VB 宏来执行此操作?

谢谢你。

编辑

请注意CODE补全(即在大多数 IDE/聪明的编辑器中是由 Ctrl+Space 执行的)和简单的WORD补全(我正在寻找的)之间存在差异。单词完成不会尝试分析当前上下文,也不会猜测您可能追求的类型/方法。它所做的一切都是尝试通过查看光标位置并搜索当前文档中已经出现的相似单词来完成您开始输入的工作。

4

4 回答 4

3

我创建了一个简单的 VS 宏:

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

将它限制在 alt-space 上,它对我有用。

什洛米

于 2012-05-21T11:00:35.750 回答
2

VS2010 可以做同样的事情吗?

默认没有。

如果不是默认情况下,谁能指出我可以插入到我的 VS2010 中的体面的 VB 宏来执行此操作?

不知道任何存在。但这可能是一个不错的项目。

于 2010-09-13T19:18:52.220 回答
1

在 Visual Studio Code (VSC) 中,getogrand 有一个扩展名“Another Word Completion”。我知道您的问题是关于 Visual Studio 的,但这可能会引起其他搜索此内容的人感兴趣。

是的,很难搜索这个,因为“代码完成”这个词更常见。

于 2018-01-31T01:11:53.757 回答
-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 http://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.

于 2012-03-21T07:05:11.253 回答