I recently saw a lot of action around Mac’s favorite editor TextMate. Force.com community has done a great job to create a full fledged IDE and various code templates for ease in working.
I like TextMate, but I am more inclined towards Force.com IDE, because of its platform neutral nature. Most of my force.com pals are either on Windows machines and few of the geeks are using Ubuntu too. So I am always more motivated towards doing something using Force.com IDE.
Force.com IDE is already doing a decent job on top of Eclipse. It gives a nice Visualforce editor, that gives syntax highlighting and code indentation based on standard Eclipse HTML Editor. I recently tried to create a couple of Visualforce code templates/snippets to quickly assist in creating the pages, and was successful in that attempt. Rest of the post describes how.
How to setup Visualforce code templates for Eclipse ?
Here are the steps
Goto Eclipse > Preferences.
Search for “Template” in the left pane preference filter box, as shown below
Hit the “New” button on extreme right side to start creating a new Template, as shown :
In the dialog next, enter tag name in the text field labeled “Name” and code snippet in text area labeled “Pattern”. Also select context as “HTML Tag”, as shown below :
Now, in any visualforce page in Force.com IDE, press CTRL + SPACE and start typing the tag name, like apex:p… In the content assist box, you will see the newly created template as shown below. Hit enter to get the template inserted in current code location.
Using the same steps as above, I have created a few templates for visualforce like
Field Label Template

CRUD FLS Permission

Creating a useful template library for Visualforce !
The good part about Eclipse templates is those can be exported and imported back via XML. I started creating a few code snippets/templates and the export for them is available in gist here.
One can easily import this GIST on the same template page using the “Import” button near the New one. Similarly exporting yours is easy too, just select templates to export and hit “Export” button.
Please join me to add more and better code templates for making Visualforce development easier in Eclipse.
Comments (7)
Anonymoussays:
October 12, 2011 at 6:24 amThis is very useful to us. I used to switch to browser from eclipse for vf page development. Thanks a lot for sharing this.
Anonymoussays:
October 12, 2011 at 6:30 amThanks Shailendra, yes browser based editor helps a bit on this part.
Anonymoussays:
October 17, 2011 at 8:34 pmAbhinav strikes again!
Anonymoussays:
October 18, 2011 at 12:12 amThanks @fractastical 🙂
Anonymoussays:
July 18, 2012 at 7:35 amI wish we could do the same for APEX code. As I see it we need this idea to be delivered before that's possible: http://success.salesforce.com/ideaView?id=08730000000g9hOAAQDo you see alternatives to waiting for the idea?
Anonymoussays:
July 18, 2012 at 7:37 amUser defined code templates for APEX classes too would be awesome. As I see it, we need to wait for this idea to be delivered before that's possible: http://success.salesforce.com/ideaView?id=08730000000g9hOAAQDo you see alternatives to waiting for the idea?
Anonymoussays:
July 18, 2012 at 7:50 amThats a good idea Soren, I think force.com tools team is focusing on browser based IDEs. So I am not sure if they will focus on enhancing desktop eclipse ide any more(apart from API version updates in every release)