Thursday, May 17, 2012

Sublime Text 2 - Snippet to create get/set methods

Sublime Text 2 is one of the most advanced editors out there, available for Windows, Mac and Linux. I'm using it on an every day basis to write my PHP applications.
Sublime Text is a sophisticated text editor for code, html and prose. You'll love the slick user interface and extraordinary features. (www.sublimetext.com)

Its snippet system allows you to create snippets that are triggered by a sequence of characters you can define, followed by tab key. The syntax is really easy. To create a snippet choose "Tools, New Snippet".

The snippet I'd like to show you today is a huge timesaver. I use it excessively in my form models in symfony2. After declaring a model variable as private or protected I need to create a get and set method for it. Copy paste and substitute the variable name was my choice until today. The following snippet allows you to use the following workflow:

  1. type 'getset'
  2. press the tab key
  3. type your variable name
  4. done.


The result: