92

Update

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

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


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

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

and setting the following

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

source = Eclipse Intellisense?

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't appear as the top suggestion. So when I naturally hit spacebar Eclipse inserts something completely wrong.

E.G. after typing Cookie I'll hit spacebar and get CookieMonster.

This seems like a bug, and happens often enough to be annoying, but even despite this I don't want spacebar to 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 always take priority over it.

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

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


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

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

davnicwil
  • 28,487
  • 16
  • 107
  • 123
  • +1 I was just fighting with that very same problem... any luck on solving this? It is very annoying to press space and get something that you did not want (you did not select it!)... This may be good for "Type declaration", but for "variable names" is not reasonable. – emgsilva Aug 15 '13 at 09:42
  • Unfortunately not. Do you know if the same problem exists in the latest version Kepler (4.3)? I haven't upgraded yet but if so I will update the question – davnicwil Aug 15 '13 at 22:20
  • 3
    Unfortunately that very same behavior takes place in Kepler (4.3)... It is really a pity. I like a lot that auto activation but it is really annoying having it making such a selection in several situations. My temporary solution is to increase slightly the activation time, so that I write most of the new variable name... but this does not work always. I will research a bit further this issue, and probably be reporting this to Eclipse, since I do think it is a bug not a feature. – emgsilva Aug 16 '13 at 06:50
  • possible duplicate of http://stackoverflow.com/questions/7371618/validate-autocomplete-in-eclipse (indicating that Indigo also already behaved like this) – herman Aug 28 '13 at 13:08
  • also possible duplicate of http://stackoverflow.com/questions/7759855/eclipse-instant-autocompletion – herman Aug 28 '13 at 13:26
  • 6
    Judging by the number of up votes on this question, and the lack of up votes on answers, it looks like Eclipse needs to fix this! – andrewb Jan 02 '14 at 04:32
  • Agreed that this is INCREDIBLY annoying! Didn't bother me until I tried PyCharm (probably the same in IntelliJ). They display autocomplete suggestions instantly but only "accept" suggestions with the Tab key and it seems like a perfect solution. – the911s Apr 16 '14 at 21:25
  • FYI, I just whipped up a plug-in real quick (below in @AndrewXu's answer about writing plug-ins) that changes the behavior in Eclipse Luna to only accept Tab and Enter as intelli-sense completion keys. – BrainSlugs83 Apr 18 '15 at 20:58

8 Answers8

31

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

callmebob
  • 6,128
  • 5
  • 29
  • 46
Pyves
  • 6,333
  • 7
  • 41
  • 59
  • 1
    Excellent, thanks a lot. I added heading to your answer so people see clearly it's for the current versions. Other answers are outdated. – callmebob Feb 13 '19 at 14:09
  • 1
    @Pyves It took me a while to accepting this newer answer, apologies, but I don't use Eclipse any more and didn't get round to verifying it. Anyway, yes, this looks like it definitively solves the problem and I'm really glad it *was* solved more than 6 years on! – davnicwil Mar 19 '19 at 12:52
  • Anyone getting a problem where the trigger suppression is not working inside the Debug Shell view? For me spacebar is triggering autocomplete. (I am on June 2019) – William Jarvis Sep 16 '19 at 10:25
  • @William Dutton possibly something to flag up in a separate bug report. – Pyves Sep 16 '19 at 12:21
26

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.

Pascalius
  • 14,024
  • 4
  • 40
  • 38
  • 2
    Looks awesome but.. it doesn't work for me in Eclipse Juno - no change in behaviour, spacebar still activates the autocomplete. Is this working for you in Kepler? Where are the toolbar button/menu items for toggling the tool mentioned in the bug thread? – davnicwil Oct 28 '13 at 20:34
  • 1
    Yes, works for me in Kepler Service Release 1. However I don't see the toolbar items either. – Pascalius Oct 30 '13 at 17:50
  • This does not work for me in Eclipse Luna SR2 (4.4.2 -- Build Id: 20150219-0600). – BrainSlugs83 Apr 18 '15 at 19:26
  • I just whipped up a plug-in real quick (below in @AndrewXu's answer about writing plug-ins) that changes the behavior in Eclipse Luna to only accept Tab and Enter as intelli-sense completion keys. – BrainSlugs83 Apr 18 '15 at 20:59
  • This worked for me on Windows 8.1 with Luna SR2 (4.4.2) Build id: 20150219-0600. – Joel Christophel May 17 '15 at 17:40
  • This now works for me, with a Mac running OSX Yosemite, with Luna 4.4.0 Build 20140612-0600. Excellent! – davnicwil Jun 05 '15 at 05:39
  • Unfortunately it seems to not work with java type proposals but other proposals seems to work correctly. (Luna 64bit version) – William Jarvis Nov 26 '15 at 15:35
  • Worked on kepler. Thank you so much. Autocomplete with space bar is so annoying! – javaProgrammer Feb 19 '16 at 17:45
  • this worked for me in ecipse mars too, you need to restart the eclipse again to take the jar loading correctly. – Alter Hu May 05 '16 at 02:22
  • Works in neon, too. Thankfully. – gcali Jul 26 '16 at 18:40
  • Odexious - how did you get it to work in Neon? When I drop it in it doesn't work and I get internal errors. – William Jarvis Jun 22 '17 at 10:43
  • 1
    @Pascalius thank you for your answer which for a long time was the best one, but now Eclipse has fixed this and made it configurable natively. This is pointed out in a newer answer, so I've accepted that one instead as it's now the best way to solve the issue. – davnicwil Mar 19 '19 at 12:50
7

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.

Andrew Xu
  • 71
  • 1
  • 2
  • 2
    For those wondering how to open this view, go to "Window"->"Show View"->"Other..." and in the filter text box start typing "plug" and then select "Plug-ins" from the box below and press "OK". – BrainSlugs83 Apr 18 '15 at 20:48
  • Also, if you're looking for a more Visual Studio like experience, I recommend just commenting out that block entirely (the default block), commenting out the '\t' block, and then finding the block that handles '\r' and '\n' (right above those two), and adding '\t' to it. -- This will give you tab completion. :-) – BrainSlugs83 Apr 18 '15 at 20:51
  • (For those that don't want to go through all this trouble, here's mine for the 64-bit version of Eclipse Luna SR2 4.4.2: http://1drv.ms/1GZhJPq -- keep in mind the changes I mentioned above.) – BrainSlugs83 Apr 18 '15 at 20:55
  • @BrainSlugs83 If you could a) post the code to github or b) add "." to completion triggers, that would be awesome. – lakemalcom Apr 22 '15 at 23:47
  • Why did you use `0x20` instead of `' '`? – Nic May 16 '16 at 00:46
  • You are a God-send. I wish I could favorite answers – Lightfire228 Mar 16 '18 at 19:25
3

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.

herman
  • 11,740
  • 5
  • 47
  • 58
0

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.

0

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.

cy198706
  • 569
  • 7
  • 15
  • MARS1 Eclipse could not be started, java.lang.RuntimeException: Application "org.eclipse.ui.ide.workbench" could not be found in the registry. – Tiina Jun 10 '16 at 14:12
-3

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

SpaceTrucker
  • 13,377
  • 6
  • 60
  • 99
  • 1
    That would remove the possibility to bring up the suggestions using ctrl+Space. What the OP wants is a way to disable selection of a suggestion using the spacebar. No key binding exists for that. – herman Aug 28 '13 at 13:11
-4

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

giskou
  • 804
  • 2
  • 8
  • 22
  • 3
    The whole problem is that I *want* the auto activation behaviour, just without spacebar doing the autocomplete – davnicwil Jan 14 '13 at 18:19