Sublime Text for Drupal - installation and configuration

Sublime Text for Drupal - installation and configuration

By Boris Baldinger 6th Juli 2012 Drupal

Welcome to the second part of my blog post series about Sublime Text 2.

In this post will explain how to configure Sublime Text for the needs of a Drupal developer.

Installation

It is very simple to install Sublime Text 2 (ST2). Just go to the Sublime Text Website, download the editor and install it like you'll do it with every other program.

Configuration

Now we are talking about the really exciting things in ST2. As mentioned in the previous blog post, out of the box the editor comes with some neat features like:

  • A small map on the right side, like a thumbnail of the code
  • A distraction free mode
  • Go-To anything
  • Split panels

But ST2's real powers are unleashed through its plugin architecture. There are tons of high quality plugins and packages already available out there.

As a Drupal developer RJ. Pittman's (phase:II) script provides an automatic and hassle free setup for your developing needs. This means running the script won't require any other further configurations but for a better understanding I recommend reading my entire post.

At this point I also want to mention his blog post about this sophisticated editor.

Configuring the text editor

To meet the requirements of Drupal coding standards, we need to configure the text formatting (Please note that my shortcuts are refer to Mac OS X). To do so go to Sublime Text 2 - Preferences - Settings User ( cmd + ) and add the lines below.

{
  "rulers": [80],
  "tab_size": 2,
  "translate_tabs_to_spaces": true,
  "use_tab_stops": true,
  "trim_automatic_white_space": true,
  "trim_trailing_white_space_on_save": true,
  "ensure_newline_at_eof_on_save": true,
  "fallback_encoding": "UTF-8",
  "default_line_ending": "unix",
  "shift_tab_unindent": true,
  "word_separators": "./\\()\"'-:,.;<>~!@#%^&*|+=[]{}`~?"
}

Save the file and restart ST2. (Source: Drupal.org)

Installing Package Control

Will Bond has created the very easy to install Package Control for ST2.

Start ST2 and go to View - Show console in the menubar (ctrl+`).

Copy and paste this command and hit the return key on your keyboard.

import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print 'Please restart Sublime Text to finish installation'

If everything worked out, and you restarted your ST2, you should be able to use the package control to install new and awesome plugins for your editor.

Press command+shift+p on your keyboard to open the command palette and type install​ followed by the return key.

Now you can search all available packages/plugins just by start typing.

Type git and you'll get a list with all packages related to Git.

Select the package you want to install, in our case just Git and hit the return key.

The plugin is now being installed for you. In this case please note that you need to have Git installed locally in order for the plugin to work.

After the installation is finished you can open the command palette by pressing cmd + shift + p and type git for a list of all available commands.

It is also possible to just type pull, push or quick in the command palette to find the command you are searching for.

In my case I had troubles to get the plugin to work. Following error message appeared.

I had to adapt the git_command configuration in the Git.sublime-settings file.

Go to Sublime Text 2 - Preferences - Browse Packages in the menubar. Search for the Git folder and open the Git.sublime.settings file by double-clicking it.

Change the git_command value from true to the path your git executable is located.

If you don't know where your git executable is stored, just open a console and type which git and you'll get the answer. In my case it was /usr/local/git/bin.

Proposed packages to install

In the short time I have been using Sublime Text 2 I the following packages have proven their use to me. You can find the list in our Wiki.

The installation of these packages works in the same way as in my example of the Git package.

Conclusion

As you can see, Sublime Text 2 is not a fully featured editor from the beginning. But the power behind the scenes is tremendous and only limited by the imagination of the plugin-developers. I will keep my eyes open for new plugins that are useful together with Drupal development. If you know about a must-have plugin that I missed, let me know and I will check it out.

In the next part of this blog series about Sublime Text 2 I will write about the very useful keyboard commands.

Kommentare

Bild des Benutzers creare site
creare site

ST2 it's my choice!

Bild des Benutzers Tony
Tony

This editor rocks! Its super fast and am ditching my Aptana Eclipse for this.

Thanks for this useful info.

Bild des Benutzers Rémy
Rémy

this is also very useful, BuildSystem for drupal coding standards:
https://github.com/sirkitree/DrupalCodingStandard

Kommentar hinzufügen

Suchformular

Neue Kommentare

  • Bild des Benutzers Daniel

    By the way, by "no documentation" I´m referring to Views Autorefresh. It is either not complete or conflicting.

    Daniel
  • Bild des Benutzers Daniel

    Thanks for this info, but can't get it working with Statuses view. There is just about no documentation or it's conflicting, even from module maintainer (on Drupal vs. Blog). I'm using the default Statuses block, which only autorefreshes the current user's status updates, does not autorefresh friends' status updates (that is how it normally works). So I added Views Autorefresh. I have tried using the maintainer's instructions, but don't get a Secondary Display on the original view unless I have a Page display within that same view. Have you tried with Statuses? Just to confirm your steps:
    1. First, I clone the original view and ADD a Contextual filter. In mine it is Statuses Comments: Created time (with operator).
    2. ADD to the cloned view the Global: Text Area, PHP. Nothing else in the Header. Have also tried it with a simple Global: Autorefresh.
    2. In the ORIGINAL view, I ADD the same Global: Text Area, PHP code. Nothing else in the Header or contextual filters?

    I've tried just about every variation and nothing works. Can you offer any advice?
    Thanks
    Daniel

    Daniel
  • Bild des Benutzers katalog

    Excellent way of explaining, and pleasant post
    to obtain data on the topic of my presentation topic, which i am going to deliver
    in college.

    katalog