Sublime 2.0 and Drupal

By Erik, Sun, 07/29/2012 - 14:39
So we've been all excited about the new version of the Sublime text editor. It has some really nice new functions like replace all as you type (Find all). And split screen functionality. One thing that was missing was the ability to jump to a definition of a function when it wasn't in the same file or an open file. To get this solved, you need to use the ctags application to generate an index of the function definitions and the Sublime CTags package to allow Sublime to take advantage of the tags. On my Mac Lion OS, the version of ctags that was available did not have the functionality that you need, so it is important to install a newer version of ctags. For me this was simply a brew install: brew install ctags Then navigating to the root of my Drupal project, I can run ctags to generate the tags index file. cd Sites/drupal ctags -R -f .tags This did not work completely, however as by default, ctags does not know that .module and .inc files are php files to be searched. The command line option for this is to add these to the mapping for php: ctags -R -f .tags --langmap=PHP:+.inc.module However, this is problematic because rebuilding tags from within Sublime will lose this mapping. To solve this, you can make --langmap=PHP:+.inc.module a default option by putting it in a .ctags file in your home directory. echo "--langmap=PHP:+.inc.module" > ~/.ctags Now the rebuild will use that mapping even when run from Sublime. To use this functionality, put the cursor within a function name that is being called and click ctrl-opt-]. This should now bring up the definition of the function you were curious about no matter where it is defined in the Drupal code base. It does not work for built-in PHP commands, but at least should work for Drupal commands. This paired with Sublime Autocompletion makes Drupal development in Sublime 2.0 much nicer.

Comments