In Terminal when I use .subl
Is there a way to run terminal commands within Sublime Text? Update Cancel. How do I set up a command line tool for Sublime Text with Rails? Ask New Question. Andy Jarrell. How can I run my program written in Sublime Text 2 inside my Mac Terminal? Sublime Text: Is there a way to save sidebar history?
It returns -bash: .subl: command not found
Anyone know how to open Sublime Text 3 from the command line in macOS?
Stickers26 Answers
I finally got this to work on my OSX box. I used these steps to get it to work:
Test
subl
from your ST installation:First, navigate to a small folder in Terminal that you want ST to open and enter the following command:
NOTE: You may need to replace
Sublime Text.app
in the command above toSublime Text 3.app
orSublime Text 2.app
depending upon where the application is stored in yourApplications
directory. The.
at the end of the above command opens the current working directory you are located in (again make sure you're in a directory that only contains a few files!).If you DO NOT get Sublime Text opening your current working directory then the next set of steps will NOT work. If nothing happens or you get an error from Terminal it will be because it couldn't find the Sublime Text application. This would mean that you would have to check what you've typed (spelling, etc.) OR that Sublime Text isn't installed!
Check '.bash_profile':
Now it's time to create your symbolic link in your
PATH
folder, BUT, before we do, let's check your profile file by usingnano ~/.bash_profile
. These are the following lines that pertain to havingsubl
work on the command line for Sublime Text:The first line sets the location where you want Terminal to look for binaries on your machine, I'm going to store my symbolic link in the
/usr/local/bin
directory - I guess you could store it anywhere provided you've notified Terminal where to look for binaries.The second line is OPTIONAL and just sets Sublime Text as the default editor. The flag
-w
has been added and you can find out more about flags by going to the Sublime Text docs: ST3 subl or ST2 sublIf you do make any edits to this file once you have closed it, you need to run the command:
to compile your newly applied edits. If you see any errors after sourcing your file get them fixed before moving to the final step.
Create a symbolic link to Sublime Text:
Now in your chosen path (I used
/usr/local/bin
) you now enter the following command:The
/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl
being EXACTLY the same location as what you entered and verified as working in STEP 1 above. The/usr/local/bin/subl
being the location of where you want the symbolic link to be located - needs to be one of yourPATH
locations from STEP 2 above.Now when you navigate to a folder or file that you want to open in Sublime Text you now just enter
subl
followed by the name of the file or.
to open the current working directory.
Hope this helps!
rs77rs77Assume :
1. You have already installed Homebrew.
2. /usr/local/bin is your $PATH.
3. You are on Yosemite or El Capitain.
Edited Aug 4th 2017: MacOS Sierra 10.12.5 works as well confirmed by David Rawson , MacOS Sierra 10.12.6 confirmed by Alexander K.
Solution : At first , run following script on Terminal app to create specific symlink.
Then,
Hit return, it should instantly pop-up Sublime app.
Chutipong RoobklomChutipong RoobklomThis worked for me (I'm using OS X Mavericks)
First, create a symbolic link:
Now you can open sublime with
I'm using oh-my-zsh on Mac OSX Mavericks and the symbol link didn't work for me, so I added an alias in my .zshrc file instead:
Open a new terminal and you should be good to go, and type subl
.
The one I will use is very simple.
this opens up the sublime text right away. You can specify the file to open as an optional parameter, e.g. to open 'myfile.txt' in the current directory.
There is a easy way to do this. It only takes a couple steps and you don't need to use the command line too much. If you new to the command line this is the way to do it.
Step 1 : Finding the bin file to put the subl executable file in
- Open up the terminal
- type in
cd ..
---------------------this should go back a directory - type in
ls
------------------------to see a list of files in the directory - type in
cd ..
---------------------until you get a folder that contains usr - type in
open usr
---------------this should open the finder and you should see some folders - open up the bin folder -------this is where you will copy your sublime executable file.
Step 2: Finding the executable file
- open up the finder
- Under file open up a new finder window (CMD + N)
- Navigate to applications folder
- find Sublime Text and right click so you get a pulldown menu
- Click on Show Package Content
- Open up Content/SharedSupport/bin
- Copy the subl file
- Paste it in the bin folder in the usr folder we found earlier
- In the terminal type in
subl
--------------this should open Sublime Text
Make sure that it gets copied and it's not a shortcut. If you do have a problem, view the usr/bin folder as icons and paste the subl in a empty area in the folder. It should not have a shortcut arrow in the icon image.
chris FrisinaThe Symlink command from the Sublime Text 3 documentation won't work as there is no ~/bin/
directory in Home location on Mac OS X El Capitan or later.
So, we'll need to place the symlink on the /usr/local/bin
as this path would be in our $PATH
variable in most cases.
So, the following command should do the trick:
Once you create the symlink correctly, you would be able to run the Sublime Text 3 like this: subl .
(. means the current directory)
Please note not to write into /usr/bin
but instead into /usr/local/bin
.The first one is for app that write themselves the binary into the system and the latest is for that specific usage of making our own system-wide binaries (which is our case here when symlinking).
Also /usr/local/bin
is read after /usr/bin
and therefore also a good place to override any default app.
Considering this, the right symlinking would be:
ln -s /Applications/Sublime Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
In OS X Mavericks running Sublime Text 2 the following worked for me.
Its handy to locate the file in the finder and drag and drop that into the terminal window so you can be sure the path is the correct one, I'm not a huge terminal user so this was more comfortable for me. then you can go to the start of the path and start adding in the other parts like the shorthand UNIX commands. Hope this helps
Jonathan BeechJonathan BeechIt works !!!! for me on MacOS Sierra 10.12.2
and find it in terminal subl
You can create a new alias in Terminal:
Copy this line and paste it into the editor:
Hit control + x, then y, then enter to save and close it.
Close all Terminal windows and open it up again.
That's it, you can now use subl filename
or subl .
Sublime Text Terminal Plugin
StickersClose Sublime. Run this command. It will uninstall it. You won't lose your prefs. Then run it again. It will automatically bind subl
.
You shouldn't pollute /usr/bin directory unless you really need to.I always use /usr/local/bin for those binaries that aren't managed by the distribution package manager. Why? Because if the package manager gets updated it'll always replace the files in /usr/bin.
So what I'd do is
sudo ln -s /Applications/Sublime Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
Adding this to ur .bashrc or .zshrc is a simple solution.
Won Jun BaeWon Jun Baeif you have subl set up to be called from the command line, the proper command to open the current directory is:
subl .
'OS X Command Line' is a link on how to make sure everything is set up.
the Tin ManYou can just add an alias
Then you should be able to open a folder or whatever with
For anyone looking for opening a file with Sublime on mac from terminal
zeeawanzeeawanThis is to get it working as an ALIAS, not a Symbolic link!
This will allow you to run additional commands in the terminal without interrupting the subl session. Using many of the symbolic link answers here (ln -s
), cause the terminal process to endure while using Sublime text. If you want the separation, create an alias in the Bash profile like so:
Test
subl
from your ST installation:First, navigate to a folder in Terminal that you want ST to open and enter the following command:
NOTE: You may need to replace
Sublime Text.app
in the command above toSublime Text 3.app
orSublime Text 2.app
depending upon where the application is stored in yourApplications
directory. The.
at the end of the above command opens the current working directory you are located in (again make sure you're in a directory that only contains a few files!).If you DO NOT get Sublime Text opening your current working directory then the next set of steps will NOT work. If nothing happens or you get an error from Terminal it will be because it couldn't find the Sublime Text application. This would mean that you would have to check what you've typed (spelling, etc.) OR that Sublime Text isn't installed!
Check and update '.bash_profile':
Now add the alias in your Bash Profile. Open it via
vim ~/.bash_profile
. These are the following lines that pertain to havingsubl
work on the command line for Sublime Text:I suggest always commenting your code in here with
##
. The second line is OPTIONAL and just sets Sublime Text as the default editor. The flag-w
has been added and you can find out more about flags by going to the Sublime Text docs: ST3 subl or ST2 sublIf you do make any edits to this file once you have closed it, you need to
source
this file in your current session or close the terminal (tab) and open a new one. You cansource
this file by running the commandsource ~/.bash_profile
Resolve any errors before moving to the final step.
I would add that if you are upgrading from Sublime Text 2, go into /usr/bin and delete your old subl first before following the same instructions above. It's worth the upgrade.
VincentVincentI achieve this with just one line in terminal (with Sublime 3):
Damjan PavlicaDamjan PavlicaI am using mac airbook open your terminal and type
Then type simple subl and file name
I am using Oh-My-Zshell and the previous aliases stated didn't work for me so I wrote a simple bash function that will allow you to open Sublime from the command line by using sublime
to open the current folder in the editor. With the addition functionality to specify a file to open the editor from.
Usage to open current folder in terminal:
Usage to open specific folder:
Summarizing the different ways you can accomplish it:
- To open sublime text from terminal
- To open a specific file in current path (or provide path to the file you need to open) using sublime text
Make your command short by introducing a new alias named 'sublime' and use it
a. open bash_profile:
nano ~/.bash_profile
b. copy this line to create the alias and save and restart terminal
alias sublime='open -a /Applications/Sublime Text.app'
c. usage: apple.txt will open with sublime text (provide file path if necessary)
sublime apple.txt
protected by MattDMoMar 10 '16 at 1:55
Sublime Text Tools For Terminal Mac Os X
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?