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

更新

这是在 Eclipse 二○一八至一二年度中修复的。这种行为仍然是默认的,但是可以配置关闭——请参阅 公认的答案了解如何配置

我将把这个问题留给子孙后代,留给 Eclipse 早期版本的用户


在 Eclipse 中,我启用了智能感知风格的 Java 建议

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

并设置以下内容

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

来源 = Eclipse 智能感知?

除了一个恼人的问题之外,这个方法非常有效。当我按下 spacebar键时,输入的令牌将自动完成,并显示建议列表顶部的内容。很公平,除了有时我会键入一个具有完全合法匹配的类/变量名,但是这个 不会显示为最佳建议。因此,当我自然地按下 spacebar时,Eclipse 插入了一些完全错误的内容。

输入 Cookie后,我将按 spacebar得到 CookieMonster

这似乎是一个错误,并经常发生足以令人讨厌,但即使这 我不希望 spacebar触发自动完成一般。我可能想要输入一个尚未声明的变量名,或者类似的东西。我想使用自动补全作为一个辅助工具,但我的自然类型应 一直都是优先于它。

我想停止 spacebar触发自动完成,要么回到使用 enter,或更好的是仍然触发自动完成与 custom键不使用普通键入。这一切都有可能吗?

我已经尝试了 内容辅助中的所有设置,但都没有用。在谷歌上搜索这个问题只会返回一系列关于禁用自动补全功能的结果。


这个问题是在 Eclipse 2018-12[4.10] 中修复的,请参阅已接受的答案

它存在于所有以前的版本中,例如 2018-09[4.9] ,光子[4.8] ,氧气[4.7] ,霓虹灯[4.6]等等。

18336 次浏览

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

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

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.

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

There is a solution on the issue tracker for this. Copy the jar in the eclipse/dropins folder. With the next restart space is diabled as autocompletion trigger.

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

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

Use a SDK version of eclipse

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.

2.In 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

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.

Same configuration as davnicwil, same issue, still on 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

  • Autocomplete+SPACE: press SPACE when autosuggestion present
  • just SPACE: press predefined key combination or sequence (e.g. SHIFT+SPACE)

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

HowTo with 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

My config file: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.

Finally worked it out.

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

Works on Eclipse Juno.

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

Eclipse 2018-12 was already patched for this!

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

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

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