score:76

Accepted answer

you might want to store those two snippets into a code template, as explained in this tutorial.

and do not forget about the possibility to quickly execute any kind of java code snippets in a scrapbook (not exactly what you want, but it can come in handy at times)

newtopian adds (in the comments)

in fact templates become much more powerful by adding variables and tabstops within, so your example above would become dbhandle ctrl+space. it would copy snippets from both parts and place your cursor right in the middle.

score:1

i have used snippets in some ides, like dreamweaver and homesite, an old coldfusion ide. i also use a lot of snippets in mysql workbench - where i type a lot of sql, very handy there.

i am now using eclipse java ee ide for web developers version indigo release and found the snippets panel in window|show view|other...|general|snippets. i was able to manipulate it and figure out how to add the code i wanted as snippets and how to use it efficiently.

score:1

use eclipse snipmatch (part of eclipse for java developers package).

  • works very well for java code snippets but also works for any other language like html, ababp, php etc.
  • you can convert any code fragment from your editor directly to a code template. highlight the code you'd like to convert to a snippet, context menu "create snippet", complete the form and done.
  • snippets can be shared via git repositories with your team members

manual: https://www.eclipse.org/recommenders/manual/#snipmatch

installation: https://marketplace.eclipse.org/content/snipmatch

score:2

the question is old but the link of the answere is older ;)

here is a nice tutorial: http://www.dansshorts.com/post/creating-snippets-in-eclipse

score:7

i ran into the snip2code plugin recently. it did the job, and i can collect and search snippets in a quick way.

score:7

well a picture worths a thousand words, what about this one?

enter image description here

score:23

eclipse also offers something very similar to the templates feature described by vonc called (would you believe) snippets. window > show view > snippets.

to add a new snippet category: right click in the snippets window and click customize... click new > new category. enter a category name if necessary (e.g. "java"). click apply. with your chosen category selected, click new > new item. enter your snippet.

to use a snippet, put the cursor where you want to insert the snippet, then double click on a snippet in the snippets window.


Related Query

More Query from same tag