Reputation: 7146
Is there an Eclipse equivalent of Visual Studio snippets, if so what is it?
Upvotes: 3
Views: 1012
Reputation: 2540
Yes, there are.
You can access the existing ones selecting the Window>Preferences dialog. Then you navigate to Java > Editor > Templates subtree.
There you can see the existing ones. The first column is both the name and the activation code. For example, the "main" template inserts a default main block at cursor position.
You can use it inside the editor by typing "main" and pressing "CTRL + space". Then a pop-up is displayed so you can choose what template you want.
In the aforementioned dialog you can both define new templates or edit the existing ones at your will.
One thing to consider is that the content assist (the CTRL+space key combination) will only bring the appropriate results if the cursor is inside the context indicated in the second column.
That is, the "while" template, for example, will only work if the cursor is inside a Java Statement, and so on.
Upvotes: 2