简体   繁体   English

VisualStudio 2010中是否有类似Eclipse的WORD完成快捷方式?

[英]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. 我最近从Java开发和Eclipse IDE切换到C#.NET和VisualStudio 2010.我真正想念的是用于完成单词的Alt + / Eclipse快捷方式。 I am NOT speaking about IntelliSense auto completion stuff. 我不是在谈论IntelliSense自动完成的东西。 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, eg string literals. 我的意思是,我希望文本编辑器能够完成在文档中某处已经存在但不会出现在IntelliSense中的单词,例如字符串文字。

In Notepad++ it is the Ctrl + Enter shortcut. 在Notepad ++中,它是Ctrl + Enter快捷键。 In Eclipse it is the aforementioned Alt + / 在Eclipse中它是前面提到的Alt + /

Can VS2010 do the same? VS2010可以这样做吗? If not by default, can anyone point me to a decent VB macro that I could plug into my VS2010 to do this? 如果不是默认情况下,任何人都可以指向一个体面的VB宏,我可以插入我的VS2010来做到这一点?

Thank you. 谢谢。

EDIT 编辑

Please mind there is a difference between CODE completion (ie what in most IDEs/clever editors is performed by Ctrl+Space) and simple WORD completion (what I am looking for). 请注意, CODE完成(即大多数IDE /聪明的编辑器通过Ctrl + Space执行的操作)和简单的WORD完成(我正在寻找的)之间存在差异。 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. 所有这一切都试图通过查看光标位置并搜索当前文档中已经出现的类似单词来完成您开始键入的工作。

I've created a simple VS macro: 我创建了一个简单的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

Bounded it to alt-space and it does the trick for me. 将它限制在alt-space中,它对我有用。

Shlomi 施洛米

Can VS2010 do the same? VS2010可以这样做吗?

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? 如果不是默认情况下,任何人都可以指向一个体面的VB宏,我可以插入我的VS2010来做到这一点?

Don't know any that exists. 不知道存在的任何东西。 But this could be a nice project to do. 但这可能是一个很好的项目。

In Visual Studio Code (VSC) there is an extension, "Another Word Completion" by getogrand. 在Visual Studio代码(VSC)中,getogrand有一个扩展名“Another Word Completion”。 I know your question was regarding Visual Studio, but this may be of interest to others searching for this who wind up here. 我知道你的问题是关于Visual Studio的,但这可能是其他搜索此问题的人感兴趣的。

Yup, hard to search for this since "code completion" term is more common. 是的,很难搜索这个,因为“代码完成”这个术语更常见。

VS2010 has that feature by default: VS2010默认具有该功能:

Shortcuts: "ALT + RIGHT ARROW" or "CTRL + SPACEBAR" 快捷方式:“ALT +右箭头”或“CTRL + SPACEBAR”

Toolbar button: (as I'm a new user, please open the screenshot picture manually at http://i.stack.imgur.com/OyiHY.png ) 工具栏按钮:(因为我是新用户,请在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 ) 相关命令对象名称:Edit.CompleteWord(请参阅: http//msdn.microsoft.com/en-us/library/xte2hh6a%28v=vs.71%29.aspx

BTW, I'm using VS2010 professional. 顺便说一下,我正在使用VS2010专业版。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM