How to add shortcut keys for java code in eclipse

一曲冷凌霜 提交于 2019-12-17 07:08:16

问题


Say I type "sout", the intellisense should expand it to "System.out.println()". Is there a way to adding such templates?


回答1:


The feature is called "code templates" in Eclipse. You can add templates with:

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

Two good articles:

  • Don't write the code, generate it
  • Custom Templates

Also, this SO question:

  • Useful Eclipse Java Code Templates

System.out.println() is already mapped to sysout, so you may save time by learning a few of the existing templates first.




回答2:


Type "Sysout" and then Ctrl+Space. It expands to

System.out.println();



回答3:


Type syso and ctrl + space for System.out.println()




回答4:


type "syso" and then press ctrl + space

OR

type "sysout" and then press ctrl + space




回答5:


This is one more option: go to Windows > Preference > Java > Editor > Content Assit. Look in "Auto Activation" zone, sure that "Enable auto activation" is checked and add more charactor (like "abcd....yz, default is ".") to auto show content assist menu as your typing.




回答6:


I've been Eclipse-free for over a year now, but I believe Eclipse calls these "Templates". Look in your settings for them. You invoke a template by typing its abbreviation and pressing the normal code completion hotkey (ctrl+space by default) or using the Tab key. The standard eclipse shortcut for System.out.println() is "sysout", so "sysout" would do what you want.

Here's another stackoverflow question that has some more details about it: How to use the "sysout" snippet in Eclipse with selected text?



来源:https://stackoverflow.com/questions/6659042/how-to-add-shortcut-keys-for-java-code-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!