Sublime Text 2? The editor that developers, developers, developers like to use. At the very least, Sublime is a common text editor for the everyday programmer. How can you use Sublime on your terminal? If you’re any programmer, you’re maneuvering through the terminal left and right, all day everyday, so you need to have an easy way to use sublime from the terminal!

By default, for Mac OS X, you don’t have Sublime binded to a command on the terminal! Let’s do show you how to do that.

Installing Sublime

You can install the stable version of Sublime on their website.

http://www.sublimetext.com/2

 

How to Set-up

We want to be able to type in:

subl

and open files.

Open a new terminal. First, we will bind the newly installed Sublime 2 (you can also do this for Sublime 3) as the subl command. We’re using a symbolic link from the binary within the Application to what we will make as globally accessible.

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

OR you can bind sublime to a sublime command for clarity instead of the abbreviation.

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

The symbolic link will create an accessible subl command to open sublime and use it to open files or folders.

We will open ~/.bash_profile with a text editor and make sure that this new sublime command will be ready whenever we open the terminal.

open -a TextEdit ~/.bash_profile

With .bash_profile, we will set the PATH variable to look inside the /usr/local/bin folder where we created the sublime link. Type the following if it is not in your ~/.bash_profile.

By exporting the path, ~/.bash_profile will refresh and export the folder for accessible binary commands whenever we open a new terminal.

Now save and exit. The first time we do this, we will not have access to the sublime command immediately. We first need to source, which means to reload the ~/.bash_profile in order to have access to our sublime command!

source ~/.bash_profile

How to Use

Open a terminal and use any of the variations of the command:

Open sublime
subl
Open a file
subl file
Open a folder
subl folder/
Open the current directory
subl .

Enjoy your new sublime command! Makes things much more convenient if you enjoy using sublime!