Wow. Last week’s opinion piece about switching from Netbeans to Sublime Text 2 has been the most popular blog post I’ve written for quite a while.

As the interest seems to be there, I thought it would be a great idea to follow up with a post taking you step by step through how I’ve set up Sublime Text 2 for PHP development, and showing you some of the useful features that you get out of the box with Sublime Text 2.

You’ll find the details below, and as a bit of an experiment, I’ve also put the details together in a series of YouTube videos for those folks who’d prefer to see ST2 in action. The video directly below is the first in the playlist, and I’ve also put the video for each feature separately further down. If you like the videos, please do click the ‘Like’ button on YouTube so that I know :)

Tip: If you can’t see any YouTube videos on this page, you might need to switch off your browser’s AdBlock plugin and then reload the page.

Install Package Control, Soda, And A Syntax Highlighting Scheme

Out of the box, Sublime Text 2 is a very good text editor. It’s so good, in fact, that I’ve seen people use it in its vanilla form perfectly happily for days and weeks before realising that it can be enhanced with third-party plugins!

The first plugin I recommend installing is Will Bond’s Package Control (installation instructions). Package Control is a plugin that automates the job of installing and upgrading plugins. After you’ve installed it, restart ST2, and then you’ll find a new “Package Control” menu option at the bottom of the “Preferences” menu.

There are over 200 community plugins currently available for ST2. You’ll find them by going into Package Control and selecting the ‘Discover Packages’ option. This takes you to the community packages webpage, where you can browse or search through the available packages. It’s worth going back and checking this page from time to time, as new packages are being added on a regular basis.

The next thing I normally do is reskin ST2. This is entirely a personal preference! Using Package Control, install the ‘Soda’ Theme plugin; this downloads the plugin, but does not activate it. Then, open up the ‘Settings – User’ preferences file (this is a JSON file), and add the following to tell ST2 to use the new theme:

"theme": "Soda Dark.sublime-theme",

You’ll notice a change straight away, but will probably need to restart ST2 for it to pick up all of the new theme properly.

Finally, I setup syntax highlighting to suit. ST2 ships with a number of these, and you can (if you wish) feed it any colour scheme originally created for TextMate. I prefer to use the ‘Phix Color Scheme’, which is available through Package Control.

Editing User Preferences

In ST2, nearly all of the configuration is done by creating and editing config files. There are no user interfaces to click through, just JSON files to edit by hand. There are a few of these files, and the basic idea is that there’s nearly always a ‘default’ config file (which contains the defaults that ST2 or its plugins ship with), and ‘user’ override files.

If you go into the Preferences menu, you’ll see a ‘Settings – Default’ option. This opens the default settings file that ST2 ships with. It’s very well documented, and well worth a browse through to see if there’s anything in there that you’d like to tweak. Don’t make changes to this file; instead, open the ‘Settings – User’ option on the Preferences menu, and put your changes in there. That way, your preferences will be preserved between ST2 upgrades.

Finding Classes With The Goto Anything Pane

There are two ways you can open files in ST2. One way is to navigate through your list of folders in the Project pane on the left hand side of the screen, clicking around with the mouse and drilling down to find the file that you’re looking for. It works … but there’s a faster alternative.

Hitting CTRL+P (CMD+P on the Mac) opens up the Goto Anything pane. Here, you can type in the name of the file that you’re looking for, and in real time, you’ll see a list of matches appear. The searching supports fuzzy matching; you can type in partial search strings, and ST2 will use them to filter out. This is a godsend for working with projects that include vendor folders (which you might not want to search inside), and any Subversion checkouts that include trunk, branches and tags.

Jump To A Line Using The Goto Anything Pane

Press CTRL+G (CMD+G on the Mac), and this brings up the Goto Anything pane, ready for you to type in a line number. As you type, ST2 goes to the line number starting to form in the input box. You can also do exactly the same by pressing CTRL+P and typing a colon at the start of the search. (CTRL+G simply opens the Goto Anything pane and puts the colon there for you as a shortcut).

You can also combine this with the file search. Hit CTRL+P and start searching for a file. Then, at the end of your search, add a colon, and then the line number that you’re looking for. This will take you to that line number in that file – all from the keyboard.

Goto A Defined Symbol Using The Goto Anything Pane

Press CTRL+R (CMD+R on the Mac), and this brings up the Goto Anything pane, ready for you to type in the name of a function or method. As you type, ST2 narrows down the list of matching functions, methods and classes in your file. You can do the same by pressing CTRL+P and typing an @ symbol at the start of the search.

You can combine this with the file search. Hit CTRL+P and start searching for a file. Then, at the end of your search term, add an @ sign, and then the name of the function or method that you’re looking for. This will take you to that function or method in that file.

Coding Quicker With The Additional PHP Snippets

The Additional PHP Snippets plugin [disclaimer: I'm the author of this plugin] provides a few simple text snippets to speed up everyday chores such as creating getters and setters, and add license text to the top of the file. It is available via Package Control.

Pull requests (or requests for features) are most welcome.

To use it, inside your PHP code, simply type ‘php-’, and ST2 will show you a list of all of the matching snippets. Select the snippet you want, hit TAB, and hey presto – the snippet is dropped into your code, ready for you to adapt as required.

Creating Doc Blocks Using DocBlockr

The DocBlockr plugin makes it very quick and easy to create doc blocks for your classes, attributes, and methods. It is available via Package Control.

To use it, open a new doc block as normal by typing ‘/**’ and then pressing ENTER. The plugin will create a template doc block for you to fill out to suit.

Real-Time Syntax Checking Using SublimeLinter

Real-time syntax checking is something you take for granted with an IDE, and it’s available in ST2 in 2 main flavours. I use the SublimeLinter plugin myself, and have had no trouble with it at all, but I know that some folks have had to use the sublime-lint plugin instead. Both are available via Package Control.

Once installed, your code is checked in real time for syntax errors. Lines that contain syntax errors are highlighted, and in the status bar at the bottom of the screen, you’ll see an explanation of what the error is.

Sometimes, the syntax error will appear to be on the wrong line – on the line below where the real problem is. SublimeLinter uses the ‘php -l’ command behind the screens – PHP’s built-in linter, and is simply reporting back exactly what the PHP runtime thinks is wrong. This might puzzle you at first if you’re used to IDEs that have their own lint algorithm built in.

Consulting The PHP Manual Using Goto Documentation

The PHP Manual is, imho, PHP’s true killer feature: all that detailed documentation, and it’s all freely available on the web (no need to go away and buy books on the language). Like many PHP developers, I’ve always got the PHP Manual open when I’m working.

The Goto Documentation plugin allows me to look up any PHP function from inside ST2. The plugin is available via Package Control, and once installed, you need to bind it to a key before you can use it. This is done by opening the ‘Key Bindings – User’ option on ST2′s Preferences menu, and adding a line like the following:

{ "keys": ["f1"], "command": "goto_documentation" }

Save the file, and you’re ready to go.

To use it, just put your text cursor on the PHP function that you want to look up, and hit your chosen key combination. Goto Documentation will switch to your browser, and search the PHP Manual for the function you’ve selected.

Handling Trailing Whitespace Using The TrailingSpaces Plugin

I know it’s a small thing, but trailing whitespace annoys the crap out of me, and I’ve always been deeply frustrated with how Netbeans never reliably stripped this from files that I created or worked on. Thankfully this isn’t a problem with ST2, and you can add the TrailingSpaces plugin to strip files in between saving them.

Testing Using PHPUnit

The PHPUnit plugin [disclaimer: I am the plugin's author] allows you to run your unit tests right from inside ST2. You can run the tests for just the file you’ve got open, or you can run all of your project’s unit tests in one go. You can also switch back and forwards between your PHP code and your unit test files, and you can quickly open your project’s phpunit.xml file.

To use the plugin, your project needs to have either a phpunit.xml file, or a phpunit.xml.dist file. This is a simple config file that tells PHPUnit where your tests are, which folders to include / ignore for code coverage purposes, and what reports / logs PHPUnit should create once the testing is done. If you’re using something like Phix, you get all of this for free, and I believe that Symfony’s standard app skeleton also includes a phpunit.xml file too.

The plugin navigates around your project, switching from file to file, using the following algorithm:

  1. It takes the full name of your PHP class, including the namespace, and uses the PSR0 autoloader algorithm to try and find the same class with ‘Test’ appended on the end. If that doesn’t work, it strips off the namespace and tries again.
  2. To find the phpunit.xml file, the plugin finds the test code first, and then searches each folder upwards for phpunit.xml or phpunit.xml.dist. If that doesn’t work, it looks in a number of pre-determined locations (defined in the plugin’s settings file), and then as a last resort it searches your whole project downwards starting from the top folder.

When you run your tests, the full output from PHPUnit appears in a panel at the bottom of ST2′s window – and that includes information on the full command executed, and which folder it was executed from. To close the panel, just hit ESC.

Alignment Plugin

This is a very simple plugin; it allows you to select some lines of code, and have all of the equals signs line up under each other. I find that this can make code (and especially array definitions) much clearer to read, but I know that it isn’t for everyone :)

Software Archaeology Using CTags

One of the ways that IDEs add a lot of value is that they truly understand the code you’re working on, and that allows them to offer features like ‘goto source definition’ et al. There’s a way you can do this in ST2, by installing the CTags plugin.

Once you’ve installed the CTags plugin, before you can use it, you need to go to the plugin’s website and follow the instructions there to get a suitable ‘ctags’ command line program installed. The plugin is a wrapper around this command’s functionality, and cannot work without it.

Then, the next step is to build a tags file. This is an index of all of your code, that the plugin can use to look up classes, functions and methods so that you can quickly jump to their definition from anywhere in your project. This is done by hitting CTRL+T and then CTRL+R, and then waiting for the ‘finished building’ message to appear in the status bar.

After that, you can navigate around your code by hitting CTRL+T and then CTRL+T again. This works particularly well for exploring code you haven’t seen before, something that I demo in the video below.

One last word of advice. CTags understands the syntax of your code, but not the strategy. It doesn’t understand the difference between trunk/ and branches/ folders, for example, or vendor/ folders. If there’s code in there, CTags by default will index it. This might be what you want, but if you find that it’s picking up duplicates that you’re not interested in, you’ll need to create a CTags.sublime-settings file in your User/ package folder to override the ctags_command setting and add in some exclusions.

What Else?

There’s one notable exception that I haven’t covered here, and that’s SublimeCodeIntel. This is a plugin that aims to bring Komodo’s autocompletion over to ST2. It’s a great idea, but my own experience with the plugin isn’t good. I’ve seen it installed on two different computers running the same OS and version of ST2, and it work fine on one and not work at all on the other. I’ve seen it stop working after a new version of the plugin was released. I’ve learned to live without it. But do go try it out, because if it works for you, you might really like it.

Are there any other ST2 plugins that you use on a daily basis? Mention them in the comments below, and I’ll check them out :)


  1. silverspacer says:
    February 28th, 2012 at 10:18 am

    Thumbs up for this post! Nice work!

  2. Radosław Mejer says:
    February 28th, 2012 at 12:33 pm

    Thanks! I’ve tried to switch to ST2 from Netbeans, but some lack of plugins made me go back.. No I can try once again :)

  3. anon says:
    February 28th, 2012 at 2:44 pm

    >Handling Trailing Whitespace Using The TrailingSpaces Plugin
    Sublime Text can do this out of the box.

    “trim_trailing_white_space_on_save”: true,

  4. Stuart Herbert says:
    February 28th, 2012 at 4:10 pm

    @anon: yes, but you need the plugin to be able to remove whitespace w/out saving the file :)

  5. Web Punk » Switching from Zend Studio to Sublime Text 2 says:
    February 28th, 2012 at 5:34 pm

    [...] I’ve just read a very nice tutorial about how to start with Sublime Text 2 published by Stuart [...]

  6. silverspacer says:
    February 28th, 2012 at 5:57 pm

    @stuart: do you know when it is possible to debug (xdebug) with st2? this would be a great feature! how do you debug your code actually?

  7. Mark says:
    February 28th, 2012 at 6:16 pm

    Thanks Stuart – made the switch last week + am loving it so far.

  8. Samuele says:
    February 28th, 2012 at 9:23 pm

    Some good svn integrated plugin for svn?

  9. Jaik Dean says:
    February 29th, 2012 at 9:10 am

    Another shortcut for “go to line 123″ is CTRL/CMD+P then type a colon followed by the line number, eg :123

  10. Jeff says:
    March 1st, 2012 at 2:32 am

    Awesome post! I’m currently drive testing Sublime 2 for Ruby and PHP coding (coming from Netbean/PHP and gEdit/Ruby), I would look at your plugin suggestions.

  11. jowe says:
    March 1st, 2012 at 10:35 am

    Thx for this good introduction!!

  12. Jonathan says:
    March 1st, 2012 at 2:35 pm

    really awesome post, I’ve been working with it for about 6 hours and I love sublime text 2. Thanks for all this info.

  13. Rafael says:
    March 2nd, 2012 at 3:54 pm

    Hi, have you tried SublimeCodeIntel package?

    CTags package has the same purpose of this one?


  14. Stephen says:
    March 2nd, 2012 at 10:10 pm

    I switched to ST2 because of your post, and the last week has been a week of great coding with a great tool!

    The only thing that I miss is the intellisense style hint windows. Working with large OO applications, it would be wonderful to have that functionality back, but with the GoToAnywhere, combined with the GoTo Declaration has almost made it a moot point!

  15. Stuart Herbert says:
    March 5th, 2012 at 10:54 am

    @Rafael: I have tried SublimeCodeIntel. Unfortunately, I’ve found it too unreliable to recommend :(

  16. pask says:
    March 19th, 2012 at 7:59 pm

    I’ve installed SublimeLing but it seems it doesn’t work.
    I’ve got a php code like this:

    and the plugin should mark both lines as wrong, but nothing happens. Is it necessary to enable the plugin or something like that?

    thank you!

  17. Waldson Moura says:
    March 23rd, 2012 at 7:56 pm

    Hi, how can I change the trailing whitespace foreground color?

  18. Steve says:
    April 16th, 2012 at 12:29 pm

    Nice post. So much great info. The main problem with ST2 and PHP is the lack of xdebug support. No debugger! Depending on your platform you might be able to use a stand alone debugger. I think osx has better support for this. If only someone would write a plugin for xdebug ST2 would be complete for PHP dev.

  19. percydalyn says:
    April 17th, 2012 at 9:59 am

    Thanks for giving such a nice video presentation,its very usefull to us.

  20. Damon says:
    April 24th, 2012 at 6:11 pm

    Great article highlighting some features I wasn’t aware of. I’ve been using SublimeText as a general editor for a while but only recently got back into PHP. I am having trouble getting SublimeLinter to work on Windows7 though. it says “php” cannot be found… but I don’t know how to go about getting it and telling it where it is.. (I’m developing on a local Apache server). Any idea how to track that down? (I’m having a similar issue with sublime linter for js and css despite having installed the windows node exe)

  21. Stuart Herbert says:
    May 9th, 2012 at 7:38 pm

    @Damon: I don’t use Sublime Text 2 on Windows, but I suspect you will need to download PHP 5.4 from, install it into c:\php, and make sure that c:\php is in your PATH.

  22. Paulo Silva says:
    May 16th, 2012 at 2:43 am

    @Damon: If you use a local Apache server you have the php.exe file inside. Just look for pph.exe in that directory and then go to Preferences > Package Settings > SublimeLinter > Settings – User and click to open the settings file, and you must write this:

    Don´t forget to change the path to your php.exe file path in your hard drive.

  23. Paulo Silva says:
    May 16th, 2012 at 2:46 am

    @Stuart Herbert

    It is possible to use php unit and ctags in windows7?

    Thanks for this excellent tutorial.

    Best regards

  24. Thiago Araújo Silva says:
    May 18th, 2012 at 1:30 pm

    Hi Stuart, thanks for the great advice! I’m just curious on why you’re using ST2 on an Ubuntu VM to do PHP development. OS X does just the same, has a command line, and you don’t need to waste system resources to run a virtualized PHP dev environment.

  25. Stuart Herbert says:
    May 21st, 2012 at 3:40 pm

    @thiago: partly because my code is targeted at Linux machines first and foremost. Using a VM (I have a set of 7-8 VMs at any one time) helps me catch problems earlier. And partly to keep my OSX desktop clean, so that I don’t have to install macports or alternatives at all.

  26. toto says:
    May 22nd, 2012 at 1:41 am

    i tried installing the package manager sublime text 2 build 2181 but it doesnt show, i restarted the application but for some reason it does not work in this build, is this happening to you as well, (build 2181)

  27. Martin says:
    May 25th, 2012 at 10:37 am

    Hi, i tried sublime but it not good as netbeans. I downloaded some plugins (quite a lot) but what i miss from netbeans:
    - showing all function parameters (and all ways function with non requirement parameters)
    - show in popup comment of the function
    - easier UI
    - the parameters/function autocomplete is not so good (css,php etc)

    What i like:
    - look more native on Mac OS X
    - minimap

    What i dont like on netbeans:
    - quite slow sometimes (java)
    - main minus: when i have mounted ftp (via transmit), sometimes on save netbeans add in css file null bytes on the end of file, so the css is not working on website…

    Any advices to make even more simillar to netbeans?


  28. Daniel Polito says:
    May 30th, 2012 at 6:15 pm

    AWESOME POST! Thanks so much for sharing this, now i love even more ST2 :D

    Congratulations for your blog.

  29. Klaitos says:
    June 11th, 2012 at 5:20 pm

    Are you working in local environment only with ST2 ?
    Great article btw !

  30. Aleksandr says:
    June 14th, 2012 at 7:19 am

    Thank you for this post. You helped me with switching from Netbeans too :)
    As for me ST2 has sometimes even more helpful auto-completion, though it works only within a single file.

    Also I will recommend few more plugins that I found very useful:

    This plugin adds PHP CodeSniffer, PHP Coding Standards Fixer, the PHP Linter and phpmd. If you install all that it requires you will get alerts when php variable is never used or undefined and much more info about possible problems in your code.

    I loved feature of Netbeans that highlight lines changed since the last commit. So I’ve made a plugin that gives you that feature for Sublime.

  31. Stuart Herbert says:
    June 20th, 2012 at 6:43 pm

    @Aleksandr: thanks for the recommendations. sublime-phpcs is a good module, and I’ll definitely take a look at Modific :)

  32. Sublime Text 2 für PHP aufrüsten says:
    June 29th, 2012 at 7:30 am

    [...] für alle wichtigen Sprachen. Wenn es zu speziell wird einfach ein Plugin installieren. Und genau hier gibt es eine super Anleitung (mit Videos) wie man sein Sublime Text 2 auf eine vollwerte IDE für [...]

  33. Amy Hendrix says:
    June 29th, 2012 at 1:59 pm

    Fantastic post – I’ve been using and loving ST2 for a while now, but even so, I picked up a bunch of tricks I didn’t know.

  34. Jared says:
    June 29th, 2012 at 6:12 pm

    For xdebug I just found this plugin. Haven’t tried it out yet but if it works. I’m saying goodbye to neatbeans.

  35. Derek Martin says:
    July 7th, 2012 at 2:30 am

    like you, i have been a netbeans user for ages. i kept hearing about sublimetext2 but didn’t know what the big deal was. i knew it didn’t have user-created-code autocomplete built-in, so it was a no-go for me. then i watched these videos. wowwww is all i can say. thanks so much. i’ll be switching asap :)

  36. Marcelo Rocha says:
    July 20th, 2012 at 12:49 am

    Great post, Thanks a lot.

    Bye Bye Netbeans.

  37. Ashley Smith says:
    August 2nd, 2012 at 11:30 am

    Thanks for the post!
    I’m getting a error when trying to use PHPUnit from Sublime:
    Cannot find file containing unit tests

    If I run phpunit from terminal all works fine.


  38. webNeat says:
    August 2nd, 2012 at 6:41 pm

    untill now I was using phpDesigner, it’s great for PHP and have a lot of useful tools. But it’s for Windows. And since I want to switch to Ubuntu, ST2 was my best choice and your topic helps me a lot to configure it :)

  39. nickf says:
    August 5th, 2012 at 10:34 pm

    Hey Stuart, thanks for the write-up on DocBlockr… it’s really cool to see people using stuff I’ve worked on. Anyway, I thought I’d point out why the surprise with the setter function. I built in some intelligence to assume some things based on the function name and one of those things is to assume that setters don’t return anything. If you have some suggestions or better ideas than mine, please do leave an issue on the github tracker.
    Cheers, Nick

  40. Rob Ingram says:
    August 7th, 2012 at 8:20 am

    Great post. I’ve been on the verge of a switch from PHPStorm for a while now.

    I’d be interested in people’s experience of whether loading up ST2 with many plugins to replicate IDE functionality has any degrading effect on performance.


  41. Daryl Tucker says:
    August 13th, 2012 at 7:07 pm

    Thanks for the great tutorial. I’ve been looking for a better JSON syntax highlighter. Any suggestions?

  42. Renato Martins says:
    August 16th, 2012 at 1:26 pm

    Hi Stuart! Thanks for sharing the article! It was very nice…

    I’ve watched all videos and each plugin is working correctly here. But I have a doubt about CTAGS… Could I do them also work to understand the javascript code?!? Or only PHP?


  43. Tom says:
    August 23rd, 2012 at 7:13 pm

    Thanks for turning me on to Sublime Text 2…It’s a really nice looking editor…But the “Go to Definition” features aren’t nearly as robust as something like NetBeans. The ctags really don’t do a great job with knowing which class your class extended so when you hit ^T ^T, it just shows you a list of all methods…Instead of being smart enough to see that you had Class::method() so it should take you to that class’ method or the to method in class it extended. I like how it doesn’t run in the JVM though, so it’s nicer on resources. It’s tough…But I do hope to one day find the perfect editor.

  44. Setting Up Sublime Text 2 For PHP Development | Blog – Leon Qiu says:
    August 28th, 2012 at 12:51 pm

    [...] Setting Up Sublime Text 2 For PHP Development [...]

  45. Robert Gonzalez says:
    September 7th, 2012 at 8:32 pm

    Any idea on how to get ZendDebugger to work with Sublime? I’ve used all of the more popular IDEs. Currently on phpStorm but would love to be able to use Storm to develop against and Sublime to debug against (build systems, reindexing, etc).

  46. Stuart Herbert says:
    September 9th, 2012 at 9:05 pm

    Sorry, no idea. I don’t use ZendDebugger at all.

  47. Matthew Fritz says:
    September 14th, 2012 at 7:18 am

    I honestly couldn’t make up my mind on ST2 until now. I was absolutely hooked on Coda 2 despite some shortcomings with PHP programming however working through your post and the various plugins has seriously opened my eyes!

    Thanks for this!

  48. Angel Munoz dV says:
    September 20th, 2012 at 8:54 pm

    Very well done and thanks for sharing it with us!

  49. Ich nehme mir Zeit für Sublime Text 2. Teil 2. » dotwired says:
    September 24th, 2012 at 2:44 pm

    [...] Setting up Sublime Text 2 fo PHP development [...]

  50. Toby Griffiths says:
    October 9th, 2012 at 5:37 pm

    Great article. Found this after picking up a load of info on Code sniffer, Mess Detector, etc at #PHPNW12, which I thing you where at, weren’t you?

    Some really useful plugins in here… thanks.

  51. Karim Ahmed says:
    October 19th, 2012 at 11:45 am

    Sounds good BUT no mention of of these key requirements of a PHP IDE:

    Debugging and profiling

    Code completion including PHP and user defined functions

    Does that mean it’s not possible?

  52. Stuart Herbert says:
    October 22nd, 2012 at 5:42 pm

    @toby: yes, I was one of the tutorial day speakers at this year’s #phpnw12 :)

  53. Improving PHP Development Workflow Efficiency With Sublime Text 2 | The Zen Coder says:
    October 22nd, 2012 at 11:58 pm

    [...] Setting Up Sublime Text 2 for PHP Development — Stuart Herbert’s take on how to set up Sublime for good PHP development workflow. Category(s): ToolsTags: editor, ide, osx, php, sublime, sublime text 2, svn, windows Tutorial: AJAX Through PHP and jQuery [...]

  54. Tips on PHP development at Personal Musing and Software Development Stuffs says:
    November 17th, 2012 at 5:38 pm

    [...] Setting Sublime Text2 for PHP Development – Love this tutorial and demo of how to configure Sublime Text2 as a fast IDE for PHP [...]

  55. nardev says:
    November 21st, 2012 at 5:22 am

    Font problem in netbeans is up to your java version, perhaps even graphic card can make problems. I also remember that i adjusted fonts in netbeans…

  56. Les says:
    November 29th, 2012 at 5:59 am

    I usually use Notepad++ and have been doing so for a number of years however my one bugbear about it (the only one really) is that I can’t seam to show the directory structure as a panel, so having to CTRL+O all the time to select a file is annoying.

    Will be taking a look at this as I found Netbeans to be too “big company” for my liking.