opensoul.org

Getting Started with Sublime Text 2

I recently switched to Sublime Text 2 from TextMate. I did not love it at first. As it goes with many of the finer things in life, Sublime is an acquired taste. It was not until I paired with a coworker for a few days that I really started to see its power. I have been using it since and have not looked back.

Here are a few tips that made it easier for me to get into it. Thanks to Anthony Garand for providing feedback and contributing to some of these tips below.

Command palette

Think of the command palette as Alfred for your code editor. Quick access to pretty much anything. Pressing ⌘⇧P will bring up the command palette where you can then scroll through a few of the options available to you: snippets, convert case, sort lines, and toggle various interface options.

Package Control

If you feel like something is missing from Sublime, then there is probably a plugin for it. The most essential plugin is Package Control, which allows you to install pretty much anything.

To use package control, press ⌘⇧P to bring up the command palette, begin to type “install”, and select “Package Control: Install Package”. This will bring up a new palette to search for packages. Find your packages and hit enter to install it. You can see in the status bar at the bottom that it is installing. Most packages will just work, but occasionally you might have to restart Sublime for the package to work.

Beat the ugly out of it

I cannot figure out a nice way to say this, so I will just say it: out of the box, Sublime is hideous. We are pompous programmers, so we cannot let that stand.

Update: The new default theme is actually much better. I still prefer the light Soda theme, but it’s no longer a necessity.

Start by installing the Soda UI theme via Package Control. This is not a theme in the syntax highlighting sense, but for the UI widgets in Sublime. Note that when plugins talk about the Packages directory in Sublime, on OS X that is in ~/Library/Application Support/Sublime Text 2/Packages.

Ahh, that is better. But the icon is ugly too. There are several replacement options on dribbble. This one is my favorite, although there is still much room for improvement.

The syntax highlighting theme that comes with Sublime is alright, but everyone has their favorite theme. Mine is Made of Code. You can use any TextMate theme by copying it to the Packages directory and going to “Preferences » Color Scheme”.

Ok, now we can stand to look at it.

Opening a project

Sublime has support for project files, but I do not use them. I prefer to just open projects from the command line. Sublime comes with a command line interface, but you need to add it to your path.

sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/bin/subl

Now you can open a file or directory from the command line.

subl -n ~/blog

I almost always edit from the current directory, so I set up a bash alias.

alias e="subl -n ."

Ok, now we have Sublime looking pretty and our project open.

Customizing Settings

Sublime is extremely configurable, but the configuration is in a few different JSON files that you have to edit by hand. But once you get familiar with them, they are not that scary.

On OS X, go to “Sublime Text 2 » Preferences”.

For each type of setting, Sublime has at least two files: defaults and custom user settings. You edit the User versions to specify the things you are overriding.

  • File Settings affect the file that you are currently editing. This includes things like your color scheme, fonts…basically, anything related to editing files.
  • Global Settings affect how Sublime itself behaves, including the UI theme, files to ignore, and window behavior.
  • Key bindings are…well, key bindings. 614 lines of glorious shortcut keys.

Take time to browse through the defaults to see all the levers and dials you can tweak. Check out my settings.

⌘p is the new ⌘t

⌘p (which is also mapped to ⌘t) brings up the Go To File palette. In addition to giving you quick access to your files, it has several features to allow you quickly jump into your files. After typing the file name, use @ in the palette to jump directly to a specific method. You can also use ⌘r to bring up the palette prefaced with @ to jump to a method in your current file.

You can also use : (colon) in the palette to go to a specific line number, and ^g will open the paletted prefaced with colon to jump to a line in the current file.

Favorite Plugins

Here is a list of some of my favorite plugins. Most of these should be available to install through Package Control. Check them out and don’t forget to browse around Packgae Control to see what else is available. Here is a complete list of packages available.

One more thing

I highly recommend you go over and read the Sublime article on NetTuts+ for many more tips and tricks to integrate into your workflow as you migrate to this new editor.

I started tweeting tips from @sublimetips on Twitter. Tweet your tips mentioning @sublimetips and I will likely retweet them.

Happy Coding!

editor and popular January 12, 2012

15 Comments

  1. wbond wbond January 12, 2012

    If you install Package Control first, you can use that to install Soda, and it will be automatically kept up-to-date.

  2. Anthony Garand Anthony Garand January 12, 2012

    @wbond Wow! That takes a lot of the setup out of that part of it, Good to know, thanks!

  3. maltize maltize January 12, 2012

    There is a RubyTest plugin available for running your unit / rspec / cucumber tests :)
    https://github.com/maltize/sublime-text-2-ruby-tests
    Also available via Package Control

  4. manlycode manlycode January 12, 2012

    I’ll have to try this. TextMate2 keeps breakin’ my heart.

  5. Luke Strickland Luke Strickland January 12, 2012

    Don’t forget fetch! Check it out http://net.tutsplus.com/articles/news/introducing-nettuts-fetch/

    It makes starting new projects super easy.

  6. jdc0589 jdc0589 January 12, 2012

    javascript formatting was one of the necessities for me.
    https://github.com/jdc0589/jsformat is included in the default package control plugin list.

  7. Matt Secoske Matt Secoske January 12, 2012

    Excellent post Brandon! Looks like you have a bit of a code formatting issue going on with the “Opening a Project” section.

    I’ve been using subl for a few months now, and even in a fairly default look & feel I’ve been loving it. This

  8. Axure Axure January 12, 2012

    Well, I guess aesthetics must be very subjective. To me the default theme is what made me switch to Sublime in an instant.

    I don’t really care that much for the features of Sublime – if an editor has decent code highlighting, it’s good enough for me. Minimap is quite sweet, I admit. But I’m very susceptible to the aesthetical aspect of things and this one beats all others by a significant margin.

  9. Marco Marco January 12, 2012

    Hello Brandon,

    Thanks for this article. I also tried Sublime and for the most part I LOVED IT, but if there is something that aches my you know what, is the auto complete. It isn’t as smooth as CODA’s. What do you think about it?

  10. rbq rbq January 16, 2012

    You can use a function instead of an alias to allow for a parameter but fall back to the current directory if it is left out.

    subl () { /usr/bin/subl -n ${1:-"."} }

  11. proyecto proyecto March 8, 2012

    thanks for this post, you make me start using Sublime Text 2 as my main IDE for php.

  12. Ahmed Ahmed May 8, 2012

    Thanks for this post.
    I’m following @sublimetips and read that some developers are able to tweet from Sublime!!!

    Has any one tried it, and how can I do that.
    By the way, Sublime is the best editor ever. Loving it.
    Also thanks a lot for @wbond and his fantastic work for all these great packages http://wbond.net/sublime_packages/community#sort-installs.

  13. Ali Ali June 6, 2012

    You mentioned that after working with John you “really started to see its power”. I’d really like to know more about this.

  14. Bill Gathen Bill Gathen October 5, 2012

    I’ve gone with rbq’s function approach, augmented by an idiosyncrasy with my setup (zsh, rvm, Mountain Lion) that requires Sublime to be opened twice in order for cmd-t and RubyTest to work:

    function e {
      subl # need to open the app first: no clue why
      subl -n ${1:-"."}
    }

    I also edited my User/Preferences.sublime-settings to include the following:

    {
      "hot_exit": false,
      "remember_open_files": false
    }

    This causes Sublime to forget what files you had open, for a more standard “open what I say to open” editor behavior.

  15. Lavberg Lavberg March 6, 2013

    cialis 10 mg effectiveness no new posts
    cialis online
    cialis 10mg or 20mg username
    – what is the deffirence between genric cialis and brand cialis

I am Brandon Keepers. I build Internet things, usually with Ruby or JavaScript. I work at GitHub and live in Holland, MI.

Popular Posts