Keybinding keys to insert custom code Eclipse

吃可爱长大的小学妹 提交于 2019-12-11 02:21:57

问题


How would I go about setting up a keybinding so when I press for example Ctrl+Shift+T in eclipse it surrounds the selected lines with a time measurer.

Like so:

1:

CODE
CODE
CODE

2: Select three lines and press CTRL+SHIFT+T

3:

long startTime = System.currentTimeMillis();
CODE
CODE
CODE
Print.pln("Time taken: " + (System.currentTimeMillis() - startTime) + "ms");

回答1:


You can achieve this by using a template, for example:

long ${newName} = System.currentTimeMillis();
${line_selection}
Print.pln("Time taken: " + (System.currentTimeMillis() - ${newName}) + "ms");

You can add this under Preferences->Java->Editor->Templates. Here you will have to give it a name, e.g. timer.

To use it, select the code press CNTRL+SPACE twice, then select timer (or whatever name you gave to the template).

Note that this will generate a name for the time variable.



来源:https://stackoverflow.com/questions/11518784/keybinding-keys-to-insert-custom-code-eclipse

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