简体   繁体   English

如何在eclipse中为java代码添加快捷键

[英]How to add shortcut keys for java code in eclipse

Say I type "sout", the intellisense should expand it to "System.out.println()".假设我输入“sout”,智能感知应该将其扩展为“System.out.println()”。 Is there a way to adding such templates?有没有办法添加这样的模板?

The feature is called "code templates" in Eclipse. 该功能在Eclipse中称为“代码模板”。 You can add templates with: 您可以添加以下模板:

Window->Preferences->Java->Editor->Templates. 窗口 - >首选项 - > Java的>编辑器 - >模板。

Two good articles: 两篇好文章:

Also, this SO question: 此外,这个SO问题:

System.out.println() is already mapped to sysout , so you may save time by learning a few of the existing templates first. System.out.println()已映射到sysout ,因此您可以先通过学习一些现有模板来节省时间。

Type " Sysout " and then Ctrl+Space . 键入“ Sysout ”,然后Ctrl+Space It expands to 它扩展到

System.out.println();

System.out.println()键入sysoctrl + space

type "syso" and then press ctrl + space 键入“syso”,然后按ctrl + space

OR 要么

type "sysout" and then press ctrl + space 键入“sysout”,然后按ctrl + space

This is one more option: go to Windows > Preference > Java > Editor > Content Assit. 这是另一个选项:转到Windows>首选项> Java>编辑器>内容辅助。 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. 查看“自动激活”区域,确保选中“启用自动激活”并添加更多字符(如“abcd .... yz,默认为”。“)以自动显示内容辅助菜单作为您的输入。

I've been Eclipse-free for over a year now, but I believe Eclipse calls these "Templates". 我已经超过一年没有Eclipse了,但我相信Eclipse称之为“模板”。 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. 您可以通过键入其缩写并按正常代码完成热键(默认情况下为ctrl + space)或使用Tab键来调用模板。 The standard eclipse shortcut for System.out.println() is "sysout", so "sysout" would do what you want. System.out.println()的标准eclipse快捷方式是“sysout”,因此“sysout”可以执行您想要的操作。

Here's another stackoverflow question that has some more details about it: How to use the "sysout" snippet in Eclipse with selected text? 这是另一个stackoverflow问题,它有一些关于它的更多细节: 如何在Eclipse中使用带有选定文本的“sysout”片段?

Step 1 -> Top apple icon -> System preference -> keyboard -> Shortcut>spotlight -> uncheck.步骤 1 -> 顶部苹果图标 -> 系统首选项 -> 键盘 -> 快捷方式>聚光灯 -> 取消选中。 Step 2 ->Eclipse -> General -> keys -> search -> content Assist -> Binding (cmd button + space) -> Apply&close. Step 2 ->Eclipse -> General -> keys -> search -> content Assist -> Binding (cmd button + space) -> Apply&close。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM