Sublime Text 3: OS X Command Line

The problem

Sublime Text 3 includes a command-line tool, subl. However, it does not work out of the box after you install the editor in OS X Yosemite.

My solution

After the installation, create a symbolic link to Sublime Text using this command:

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

where

  • ‘/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl’ is the location that the application is stored in your Applications directory.

  • ‘/usr/local/bin’ is the chosen path you want the symbolic link to be located.

To use Sublime Text as the editor for many commands that prompt for input, set your EDITOR environment variable:

export EDITOR='subl -w'

where the flag -w will cause the subl command not to exit until the file is closed.

You can also set your default editor in Git with this command:

git config --global core.editor "subl -n -w"

Originally published at victorleungtw.com on February 18, 2015.