Eclipse autocompletion problem

2019-03-15 05:34发布

问题:

Just installed Eclipse Helios (Win7 64) and I'm having a strange problem. I type syso-Ctrl-Space which is expected to complete to System.out.println("") but it doesn't work! I searched the web for about an hour now, I set Preferences > Java > Editor > Content Assist to defaults, nothing. Everything else seems to work. Ideas?
To be clear: the shortcut works, it completes everything except "syso" as seen so far, on syso (also tried sysout) it says "No Default Proposals". I couldn't find this kind of shortcuts in the Content Assist, but I set them to default anyway.

回答1:

If you still cant get auto-completion working,try enabling the Template proposals under Content assist menu.This is the exact location,

Windows->Preferences->Java->Editor->Content Assist->Advanced

And make sure you have only one entry for syso(Under Templates menu).



回答2:

I believe the right template is "sysout" and I believe this can be configured somewhere but could not tell you where. Try sysout and then Ctrl+Space It's a template, you can find all templates under

Window -> Preferences -> Java -> Editor -> Templates

There you can see that the template name is "sysout" this will then trigger the string substitution for System.out.writeln() but you can change both the template name (if you prefer syso) and/or the actual code produced by invoking the template

Cheers



回答3:

I am using Eclipse Galileo and had the same problem. Even after trying the above proposed solutions but it didn't work. After making the below change it finally comes out.

  1. Go to Windows->Preferences->Java->Editor->Templates
  2. Select sysout template and edit it.
  3. Change the context from Java statement to Java.

And it worked for me. I hope this will be helpful for you.



回答4:

As Peter stated, it is under Window -> Java -> editor -> templates. Look for the line with the following values.

sysout "Java Statements" "Print to standard out" "on"

the preview should be as follows...

System.out.println(${word_selection}${});${cursor}


回答5:

Your cursor needs to be located in a place where it would be legal to get that line. If your cursor is within a method definition and you type syso you will get the replacement. However if your cursor is in the portion of the text outside of any method definition, say where you declare variables for your class for instance, then syso will not suggest the illegal line system.output.println();.

I had this problem, read all the answers here, became convinced that it MUST be working in my copy, and realized I had been typing syso BELOW the closing } of my last method instead of in the method.

Eclipse on!



回答6:

You may try to set the shortcut of Content Assist with ALT+L, if it works, then you can choose your favorite shortcut again. (The shortcut Ctrl+Space conflicts with the shortcut of switching input method). In eclipse on linux, the shortcut of Word Completion is ALT+/, so if you set this as the shortcut of Content Assist it also conflicts.)



回答7:

Just go to the below address:

Windows->Preferences->Java->Editor->Content Assist->Advanced

and click restore default..........that's all

its work like a charm again.



回答8:

Also check in this eclipse menu: Windows -> Preferences -> Java -> Appearance -> Type Filters

If you see java.* or javax.* here then try removing it (or Restore Default will do the job) and see that works, it did for me.



回答9:

Just found the solution for Eclipse Luna: write syso and press CTRL+Space and click on "enable intelligent code completion" and you are set. I am sure you can find it somewhere in the options as well but this way it is fast and easy!



回答10:

DIRTY WORKAROUND: You can try out the following AutoHotkey-Code if you're still struggling like I am (STILL haven't been able to fix it myself)

#persistent
#ifwinactive ahk_class SWT_Window0  ; eclipse java
:*:syso::
sendraw System.out.println()`;
loop, 2
    send {left}
return
#ifwinactive

You need to write this in a .ahk file and run it (AutoHotkey needs to be installed). You might wanna put this file into your startup folder. It's a very useful tool, you might wanna expand it one day.



回答11:

You might have overlapping shortcuts.. Goto 'Overview' than the 'Keys' subsection. Type "ctrl +space" in the 'filter text' section. You should see the "content assist" and probably another command with the same shortcut. If another shortcut does exists, change its shortcut to something else.