Shortcut to Opening a File in Sublime from the Command Line

Talia Marcassa
2 min readApr 13, 2017

One thing we spend a lot of time doing in class is opening new files in our Text Editor. My Text Editor of choice is Sublime Text 3 and I use oh-my-zsh as my command line shell.

With that in mind, I set about Googling how to setup a shortcut to open my files from the command line in Sublime Text 3.

The first article I found was Sublime Text’s own documentation, found here. I ran this command and all seemed to be going well, until I quit my terminal and re-opened it which meant that the command was forgotten.

Sad face.

So! I learned about aliases in Zsh.

To install your own Zsh alias follow these steps:

  1. Navigate to your Root Directory (cd ~)
  2. List all the files in this director (ls -A)
  3. Open the .zshrc file. This is where a host of options for your Zsh shell are stored. (Open .zshrc)
  4. This file should then open in TextEdit. Navigate to the bottom of the file and under “Example Aliases”, copy in the following code:
alias subl="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"

The very key detail of the above line of code is the quotes. If you copy and paste text from another Stackoverflow answer or tutorial, make sure you then replace the quotes with ones you copy and paste from the .zshrc file itself. I cannot stress this enough. I fought with this command for hours until I realized all I needed was to replace the quotes.

If the above command doesn’t work for you, please let me know (@talialongname)! But also check the following:

  • Follow the path from applications to the ‘subl’ file that should be placed in your ‘bin’. If that isn’t there, go back to the Sublime Text docs. Navigate to your Applications folder from your command line starting with cd /
  • Check that you are indeed using Sublime Text 3 and that Sublime Text is in your Applications folder.
  • If all else fails, head on over to StackOverflow!

Good luck and happy opening!

--

--