停止空格键按键触发 Eclipse 中的自动完成

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14297735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 19:47:31  来源:igfitidea点击:

Stop spacebar keypress from triggering autocomplete in Eclipse

javaeclipse

提问by davnicwil

Update

更新

This was fixed in Eclipse 2018-12. This behaviour is still default, but can be configured off - see the accepted answerfor how

这已在 Eclipse 2018-12 中修复。此行为仍然是默认行为,但可以将其配置为关闭 - 请参阅已接受的答案以了解如何

I'll leave the question as it was for posterity, and for those on earlier versions of Eclipse

我会留下这个问题,因为它是为了后代,对于早期版本的 Eclipse



In Eclipse, I've enabled intellisense-style suggestions for Java by going to

在 Eclipse 中,我通过以下方式为 Java 启用了智能感知风格的建议

Window -> Preferences -> Java/Editor/Content Assist

and setting the following

并设置以下内容

Auto activation delay (ms) -> 0
Auto activation triggers for Java -> .(abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ

source = Eclipse Intellisense?

源 = Eclipse 智能感知?

This works brilliantly, apart from one annoying problem. When I hit spacebar, the token being typed is autocompleted with whatever is at the top of the suggestions list. Fair enough, except that sometimes I'll type a class/variable name with an exact legal match, but this won'tappear as the top suggestion. So when I naturally hit spacebarEclipse inserts something completely wrong.

除了一个烦人的问题外,这非常有效。当我点击 时spacebar,输入的标记会自动完成,并使用建议列表顶部的任何内容。很公平,除了有时我会输入一个具有完全合法匹配的类/变量名称,但这不会作为最重要的建议出现。所以当我自然而然地点击spacebarEclipse 时,插入了一些完全错误的东西。

E.G.after typing CookieI'll hit spacebarand get CookieMonster.

EG打字后Cookie我会打spacebar并得到CookieMonster

This seems like a bug, and happens often enough to be annoying, but even despite this I don't want spacebarto trigger autocomplete in general. I may want to type a variable name which hasn't been declared yet, or something similar. I want to use autocomplete as a helper tool, but my natural typing should alwaystake priority over it.

这似乎是一个错误,并且经常发生令人讨厌,但即使如此,我也不想spacebar触发自动完成。我可能想输入一个尚未声明的变量名,或者类似的东西。我想使用自动完成作为辅助工具,但我的自然打字应始终优先于它。

I'd like to stop spacebartriggering autocomplete, and either fall back to using enter, or better still trigger autocomplete with a customkey not used in ordinary typing. Is any of this possible?

我想停止spacebar触发自动完成,要么回退到 using enter,要么最好仍然custom使用普通打字中不使用的键触发自动完成。这有可能吗?

I've played around with all the settings in Content Assistto no avail. Googling the question just returns a bunch of results about disabling the autocomplete feature.

我已经尝试了Content Assist 中的所有设置,但无济于事。谷歌搜索这个问题只会返回一堆关于禁用自动完成功能的结果。



This issue is fixed from Eclipse 2018-12 [4.10]see the accepted answer

此问题已从 Eclipse 2018-12 [4.10] 修复,请参阅已接受的答案

It's present in all prior versions, i.e. 2018-09[4.9], Photon[4.8], Oxygen[4.7], Neon[4.6], etc..

它存在于所有以前的版本中,即2018-09[4.9]、Photon[4.8]、Oxygen[4.7]、Neon[4.6] 等。

采纳答案by Pyves

Eclipse 2018-12 was already patched for this!

Eclipse 2018-12 已经为此打了补丁!

A patch for Bug 348857was recently merged to the Eclipse project and was released as part of Eclipse 2018-12. You can download that version here.

针对错误 348857的补丁最近已合并到 Eclipse 项目中,并作为Eclipse 2018-12 的一部分发布。您可以在此处下载该版本。

You now have a new option to disable all insertion triggers apart from enter, which will prevent spacebarfrom causing autocompletion.

您现在有一个新选项可以禁用除 之外的所有插入触发器enter,这将防止spacebar导致自动完成。

Simply go to Preferences...-> Java-> Editor-> Content Assist(or Window-> Preferences-> Java-> Editor-> Content Assiston Windows) and select Disable insertion triggers except 'Enter', as shown in the screenshot below: Disable insertion triggers preferences

只需转到Preferences...-> Java-> Editor-> Content Assist(或Window-> Preferences-> Java-> Editor-> Content Assiston Windows)并选择Disable insert triggers except 'Enter',如截图如下: 禁用插入触发器首选项

回答by Pascalius

There is a solution on the issue trackerfor this. Copy the jarin the eclipse/dropins folder. With the next restart space is diabled as autocompletion trigger.

问题跟踪器上有一个解决方案。将jar复制到eclipse/dropins 文件夹中。随着下一次重新启动空间被禁用作为自动完成触发器。

https://bugs.eclipse.org/bugs/show_bug.cgi?id=348857

https://bugs.eclipse.org/bugs/show_bug.cgi?id=348857

Eclipse 12-2018 and newer:This is working natively, check Pyves answer.

Eclipse 12-2018 及更新版本:这是本机工作,检查 Pyves 答案。

回答by Andrew Xu

Use a SDK version of eclipse

使用 Eclipse 的 SDK 版本

1.open Plug-ins View and find org.eclipse.jface.text, right click, choose import as Source Project. After import, you find it in your workspace.

1.打开Plug-ins View,找到org.eclipse.jface.text,右键,选择import as Source Project。导入后,您可以在工作区中找到它。

2.In src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java

2.在src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java

char[] triggers = t.getTriggerCharacter();
if(contains(triggers,key))

change to

改成

if(key!='='&&key!=0x20&&contains(triggers,key))

3.Export org.eclipse.jface.text

3.导出org.eclipse.jface.text

Right click the project folder of org.eclipse.jface.text, choose export-->Deployable plugins and fragments, next, destination choose archive file, finish. Replace the one in eclipse/plugins with the one you generate.

右键单击org.eclipse.jface.text 的项目文件夹,选择export-->Deployable plugins and fragment,然后目标选择归档文件,完成。将 eclipse/plugins 中的那个替换为您生成的那个。

回答by herman

The spacebar has been a key to select the autocomplete even in Indigo. To my knowledge, this can't be configured. In fact, that is probably why the delay exists.

即使在 Indigo 中,空格键也是选择自动完成的关键。据我所知,这是无法配置的。事实上,这可能就是延迟存在的原因。

I suggest setting the delay to some optimal value that allows you to type things like private void ...comfortably without triggering suggestions for privateand void. Then in case you get a suggestion because you waited too long, press Escape to abort Content Assist.

我建议设置延迟一些最佳值,可以让你型喜欢的东西private void ...舒服,而不会触发的建议privatevoid。然后,如果您因为等待时间过长而收到建议,请按 Escape 中止 Content Assist。

回答by user3178008

Same configuration as davnicwil, same issue, still on eclipse 4.4.

与 davnicwil 相同的配置,相同的问题,仍在 eclipse 4.4 上。

Solution: Intercept (hook) SHIFT+SPACE (press and hold) on (editor-window) eclipse and replace it with ESC,SPACE (sequence). Now you my decide between

解决方案:在(编辑器窗口)eclipse 上截取(挂钩)SHIFT+SPACE(按住)并将其替换为 ESC,SPACE(序列)。现在你我决定

  • Autocomplete+SPACE: press SPACE when autosuggestion present
  • just SPACE: press predefined key combination or sequence (e.g. SHIFT+SPACE)
  • 自动完成+空格:出现自动提示时按空格键
  • 只是空格:按预定义的组合键或序列(例如 SHIFT+SPACE)

On windows you may use http://www.heise.de/download/activaid.html(you can also use AutoHotkey, java native hook, ...)

在 Windows 上,您可以使用http://www.heise.de/download/activaid.html(您也可以使用 AutoHotkey、java native hook 等)

HowTo with ActivAid:

如何使用 ActivAid:

  1. Open Ac'tivAid, select "UserHotkeys"
  2. click on "+", set a description
  3. click on "short cut", press e.g. SHIFT+SPACE
  4. Command: "{ESC}{SPACE}" (without quotes)
  5. click "+", select eclipse editor frame, press ENTER
  6. click OK, OK in Ac'tivAid
  1. 打开Ac'tivAid,选择“UserHotkeys”
  2. 点击“+”,设置描述
  3. 单击“快捷方式”,按例如 SHIFT+SPACE
  4. 命令:“{ESC}{SPACE}”(不带引号)
  5. 点击“+”,选择eclipse编辑器框架,按回车
  6. 单击确定,在 Ac'tivAid 中确定

My config file:activAid/settings/ac'tivAid.ini:[UserHotkeys]

我的配置文件:activAid/settings/ac'tivAid.ini:[UserHotkeys]

Hotkey11=+Space
Path11=<Send>{ESC}{SPACE}
Description11=Eclipse Shift+Space -> Esc,Space
Category11=
Application11=ahk_class SWT_Window0

You may also remap keys on non-english keyboards with "HotStrings", e.g. ?->{,?->} etc.

您还可以使用“HotStrings”重新映射非英语键盘上的键,例如 ?->{,?->} 等。

回答by cy198706

Finally worked it out.

终于搞定了。

Try download this org.eclipse.jface.text.jarand copy it to your plugin folder(Typically eclipse/plugin). Do not forget to backup your own one.

尝试下载此org.eclipse.jface.text.jar并将其复制到您的插件文件夹(通常为 eclipse/plugin)。不要忘记备份你自己的。

Works on Eclipse Juno.

适用于 Eclipse Juno。

If the link doesn't work, comment on this, thanks.

如果链接失效,请评论,谢谢。

回答by giskou

You could disable Auto activation via the check box in

您可以通过复选框禁用自动激活

Window -> Preferences -> Java/Editor/Content Assist

and activate the auto-complete feature on demand. The default hotkey for this is

并根据需要激活自动完成功能。这个的默认热键是

CTRL+Space

CTRL+Space

回答by SpaceTrucker

In Eclipse go to Window -> Preferences -> General -> Keys and remove the binding for the command Content Assist.

在 Eclipse 中,转到 Window -> Preferences -> General -> Keys 并删除命令 Content Assist 的绑定。