Sublime Text 2 environment for PHP development

Sublime Text 2 environment for PHP development

First of all, Sublime Text is one of those type of tools that make you wonder how life was even possible before of it. I love it, everyone I know loves it, I wish it could have my babies and the only programmers I know that don’t love it are either gay or VIMmers. While I have to admit there are some more powerful IDEs out there and that the people who use them are probably more skilled than I am, I prefer to stand my ground claiming that programming as an activity, should above everything be pleasant.

I had to force myself into using other IDEs, mostly because of their particular features and my eagerness to get sh** done faster. Then of course, some years ago I tried Sublime Text and couldn’t let go since. So if you ever see me using something else, I must be doing embedded programming, using some dedicated IDE because of its painless debugging and actual microcontroller programming capabilities.

Oh deer! Whatever happened to minimal writing… More to the point, Sublime Text is great – you can find tons of resources on the website including documentation for its Python based plugin API. Also, there’s this super detailed and informative article written by Stuart Herbert who’s an awesome software engineer with early contributions to quite a few open-source projects, most notably Gentoo Linux and Generic NQS.

Sublime Text 2 Screenshot

The following part is sort of a humble guide that could be entitled 5 things you should do after installing Sublime Text. It will describe in a few steps how to get a bare minimum of extra awesomeness that this IDE deserves.

1. Install package control
From the Preferences menu, go to Browse Packages, go one folder up and enter Installed Packages. This is where we copy Package Control.sublime-package, or alternatively try this code directly in the ST2 console (Ctrl + `).

2. Install the Phoenix Theme and pick a nice color scheme – I’d go for Dark Blue, so Ctrl + Shift + P and look up the Phoenix Theme. Unfortunately, it seems that as of somewhere around August the 24th, the Phoenix Theme started breaking Sublime Text’s UI badly so a switch is in order (too bad, it really was a nice theme).

2. Install custom theme / color scheme

Well anyway, did some research and put together a little something: Void Theme + Tron Contrast Color Scheme. Of course, 99.9% of the credit and all the thanks go straight to Noel Cower, Dayle Rees and all the people they recursively thanked themselves. Quick installation thingy:

cd ~/.config/sublime-text/Packages
git clone git@github.com:mjohnson8165/st-theme-freesia.git 'Theme - Freesia'

If for any sad reason you can’t do that (i.e. not on github yet or your SSH keys are missing), you can do it the hard nasty ass h4xX0r way:

cd ~/.config/sublime-text/Packages
wget https://github.com/mjohnson8165/st-theme-freesia/archive/master.zip -O theme.zip
unzip theme.zip && rm theme.zip && mv st-theme-freesia-master 'Theme - Freesia'

3. Install the DockBlockr plugin

Great package for Sublime that makes documenting code a breeze. The README.md on github provides a few basic usage examples.

4. Install the Alignment plugin

One of Will Bond’s (yeah, the same guy who made Package Control itself) best packages for ST, Alignment helps you write clean readable code – just select the lines that need aligning and do a Ctrl + Alt + A.

5. Install the GitGutter plugin

One of JD Isaacks’ masterpieces, GitGutter will make you love yourself for using Git with your projects as it displays small icons in the gutter area of Sublime, indicating whether a line has been inserted, modified or deleted. For a list of other useful options and their description, follow the github link above.

6. Install the SublimeTODO plugin

While there are many plugins out there for handling TODO list integration, this one is the best one I came across. For some reason yet unknown to me, on Rob Cowie’s page (the author) the project title says [Deprecated].

Could be maybe because he also launched the SublimeTodoReview plugin which seems to be strictly for Sublime Text 3. Anyway, just to make sure the original version isn’t going anywhere I forked the project and you can install it manually like this:

cd ~/.config/sublime-text/Packages
git clone https://mjohnson8165@github.com/mjohnson8165/SublimeTodo.git

7. Tweak the User Preferences:

{
    "bold_folder_labels": true,
    "color_scheme": "Packages/Theme - Freesia/Tron Contrast.tmTheme",
    "font_face": "Consolas",
    "font_size": 11,
    "freesia_borderless": true,
    "freesia_large_tabs": true,
    "freesia_small_vscroll": true,
    "highlight_modified_tabs": true,
    "ignored_packages":
    [
        "Vintage"
    ],
    "line_padding_bottom": 1,
    "line_padding_top": 2,
    "theme": "Void.sublime-theme",
    "todo": {
        "folder_exclude_patterns": [
            "bootstrap2",
            "bootstrap3",
            "tmp"
        ],
        "file_exclude_patterns": [
            "*.md",
            "*.min.js",
            "*.map.",
            "*.log",
            "*.sql"
        ]
    },
    "update_check": false
}

I’ve updated the config lines just above to remove any trace of the Phoenix Theme and gotta admit I had a few short moments of nostalgia… But then of course, I made my own – with blackjack and hookers:

Sublime Text - Void Theme + Tron Contrast Scheme

So there you have it – I’m really trying to be modest here, but this is the ultimate theme and Harry Nilsson can suck on a coconut ’cause I put the lime in Sublime!

Almost forgot… here are some useful keyboard shortcuts:

  • Ctrl + Tab : Just like in pretty much any tabbed application, switch between tabs
  • Ctrl + W : Close a tab… dooh~
  • Alt + Shift + [number] : Set the number of columns / rows for the layout
  • Ctrl + Shift + [number] : Move the current tab to the [number] layout group
  • Ctrl + [number] : Focus layout group
  • Ctrl + K – B (release K before pressing B) : Toggle sidebar
  • Ctrl + F / Ctrl + H : Find / Replace
  • Ctrl + Shift + F / Ctrl + Shift + H : Find / Replace in the entire project
  • Alt + R : Find using regular expressions (only while Find / Replace panel is open)
  • Alt + C : Case sensitive search (only while Find / Replace panel is open)
  • Ctrl + P : GoToAnything panel – thanks to the fuzzy search algo, it is very useful for opening any file in the project in a split second
  • Ctrl + R : Go to function definition in current tab
  • Ctrl + Shift + P : Quick command panel – I use it mostly to install / remove packages or change the syntax mode for the current tab
  • Ctrl + Alt + P : Switch project / workspace
  • Ctrl + ] : Indent a line or a block of code to the right
  • Ctrl + [ : Indent a line or a block of code to the left
  • Ctrl + D : Select the next occurrence of the selected text
  • Alt + F3 : Select all occurrences of the selected text
  • Ctrl + ` : To avoid confusion – that is the backtick character – open the console
  • Ctrl + Shift + D : Duplicate current line (doesn’t need to be selected)
  • Ctrl + Shift + C : Open color picker (very useful when writing CSS)
  • F11 : Full screen mode
  • Shift + F11 : Distraction Free Mode (Full screen on steroids)
  • Ctrl + / : Toggle inline comments ( // ) for a line or a block of code
  • Ctrl + Shift + / : Toggle block comments ( /* … */ ) for a line or a block of code

I probably use more than just these on a regular basis, but can’t think of any other at the moment. However, I am sure there are many more useful others that I don’t even know about and probably should.

They really help speed up the coding process and really aren’t a pain in the ass to get used to, plus these are just Sublime’s features. Almost every plugin extends the IDE’s functionality considerably and comes with its own set of keyboard shortcuts for lightning-fast coding…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s