Stop spacebar keypress from triggering autocomplete in Eclipse
Asked Answered
U

8

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

Upholster answered 12/1, 2013 at 20:39 Comment(8)
+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.Carlie
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 questionUpholster
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.Carlie
possible duplicate of #7372118 (indicating that Indigo also already behaved like this)Runway
also possible duplicate of #7760355Runway
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!Peewee
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.Westonwestover
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.Dogy
I
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

Inducement answered 20/12, 2018 at 22:15 Comment(4)
Excellent, thanks a lot. I added heading to your answer so people see clearly it's for the current versions. Other answers are outdated.Stalagmite
@Inducement 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!Upholster
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)Concordat
@William Dutton possibly something to flag up in a separate bug report.Inducement
S
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.

Stern answered 26/10, 2013 at 7:24 Comment(12)
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?Upholster
Yes, works for me in Kepler Service Release 1. However I don't see the toolbar items either.Stern
This does not work for me in Eclipse Luna SR2 (4.4.2 -- Build Id: 20150219-0600).Dogy
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.Dogy
This worked for me on Windows 8.1 with Luna SR2 (4.4.2) Build id: 20150219-0600.Recognizee
This now works for me, with a Mac running OSX Yosemite, with Luna 4.4.0 Build 20140612-0600. Excellent!Upholster
Unfortunately it seems to not work with java type proposals but other proposals seems to work correctly. (Luna 64bit version)Concordat
Worked on kepler. Thank you so much. Autocomplete with space bar is so annoying!Acetyl
this worked for me in ecipse mars too, you need to restart the eclipse again to take the jar loading correctly.Lever
Works in neon, too. Thankfully.Happygolucky
Odexious - how did you get it to work in Neon? When I drop it in it doesn't work and I get internal errors.Concordat
@Stern 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.Upholster
B
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.

Brainstorming answered 20/2, 2014 at 5:19 Comment(6)
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".Dogy
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. :-)Dogy
(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: 1drv.ms/1GZhJPq -- keep in mind the changes I mentioned above.)Dogy
@Dogy If you could a) post the code to github or b) add "." to completion triggers, that would be awesome.Monte
Why did you use 0x20 instead of ' '?Bate
You are a God-send. I wish I could favorite answersDrummer
R
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.

Runway answered 28/8, 2013 at 13:16 Comment(1)
I've had only limited success from increasing the delay.Server
I
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.

Interlock answered 5/11, 2014 at 20:54 Comment(0)
C
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.

Crowley answered 1/12, 2014 at 8:54 Comment(1)
MARS1 Eclipse could not be started, java.lang.RuntimeException: Application "org.eclipse.ui.ide.workbench" could not be found in the registry.Caudate
A
-3

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

Averroes answered 28/8, 2013 at 13:6 Comment(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.Runway
C
-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

Chyack answered 14/1, 2013 at 17:48 Comment(1)
The whole problem is that I want the auto activation behaviour, just without spacebar doing the autocompleteUpholster

© 2022 - 2024 — McMap. All rights reserved.