Open Sublime Text From the Command Line Using Subl.exe (Windows)
Sublime Text 3 was recently updated to Build 3065. If you’re not on the bleeding edge dev builds, you won’t see updates too often. When they happen, though, there’s always some fun stuff in the update.
In this latest update, two things stood out. One is having cool icons in the sidebar next to our files, and the other is geared towards Windows users. Windows users now have a command-line helper in
Mac users have had this for a long time (
subl) and it’s great to see the equivalent come to Windows.
What is the Sublime Command Line Helper?
For those of you that don’t know what it is and why it’s so great, let’s talk about how we currently add files and folders to Sublime.
The options that were available were to:
- Drag and drop a file/folder into Sublime
- Use the Open commands in the menu
Now with the command line helper, we can add files/folders to Sublime straight from the command line!
Let’s take a look at how we can get everything set up. Go ahead and update Sublime Text to make sure you have the latest Build 3065 (Help -> Check for Updates). After the update, you may be able to go into your command line and type:
This should open up Sublime Text.
If you get the error command not found then we’ll need to set some things up.
Adding Sublime to Your PATH
The command wasn’t found because Sublime Text isn’t in your PATH. The things in your Windows PATH are accessible via the command line so we’ll need to go ahead and add it. We will need to go into our Environment Variables settings. Do this by going to:
System Properties -> Advanced System Settings -> Advanced -> Environment Variables
A nice shortcut to do this is to open up your command line and typing
sysdm.cpl. That will open up the window we need.
Create a New System Variable Create a new system variable called
SUBLIME that will point to the folder of your Sublime installation.
Add the System Variable to Your PATH Add the following to the end of your PATH variable:
Now if you restart your command line (I’m using a mixture of Git Bash and ConEmu), then you should have the
subl.exe command at your disposal!
subl.exe Into New Sublime Window
You now have the ability to open a file or folder in a new Sublime window. Just find the one you want and type:
- subl.exe file_name
- subl.exe folder_name
subl.exe Into Same Sublime Window
To open files or folders into the current Sublime Text window, just add the
--add modifier to your subl.exe command.
- subl.exe file_name --add
- subl.exe folder_name --add
With every version, Sublime Text just keeps getting better and better. With the addition of
subl.exe this brings a long wanted feature that was on Mac to the Windows users.
For more Sublime Text goodness, check out this article: