Launch Sublime Text in Windows Command Line

Share httpJunkie.com on..
Tweet about this on TwitterShare on FacebookShare on Google+Share on TumblrEmail this to someone

As I start to delve into the JavaScript development world, I am using the command line more and more often as well as ditching Visual Studio for small projects or demos, etc.. Either way, I was looking for a way to launch Sublime Text from the Windows Command line. Below are the steps I took to get it working.

My problem was that I was running into files like index.jade or something that just didn’t make sense to edit with notepad. For jade files I have special formatting options set up in Sublime so I wanted to take advantage of that from the command line.

My goal was to be able to cd into a directory or target a directory and just like I could edit a file with notepad by running:

C:\Demos>notepad index.jade

Instead be able to edit my file with Sublime Text (2 or 3) like this:

C:\Demos>subl index.jade

This instruction will work with any text editor you might have, just change the paths to the program directory and whatever.exe.

Step 1) Open your environment variables

Pre Win 8: Right click on My Computer > Properties > Advanced > Environment Variables
Win 8+: Search Settings for: ENV and select: Edit environment variables for your account

Step 2) Under User variables click on PATH and edit. If you have any prior variables in here you will need to add a semicolon to the end of that variables before creating a new one. Add the path to the Sublime Text Directory. Here is an example where I have a prior variable for NodeJS

C:\Program Files\nodejs\;C:\Program Files\Sublime Text 3;

If my Path was empty I would just put..

C:\Program Files\Sublime Text 3

..and not worry about the semicolon used to separate my path variables.

Click OK and close the System Properties

Step 3) run my command line (AS ADMINISTRATOR) and switch to the Sublime Text directory. I used the following command to get me there:

C:\>cd C:\Program Files\Sublime Text 3

Now my prompt has me inside the Sublime directory. Now run the following command:

C:\Program Files\Sublime Text 3>mklink subl.exe sublime_text.exe

if you would rather use sublime as the keyword in the command line or any other word for that matter, just change the first link in that command.. like this:

C:\Program Files\Sublime Text 3>mklink sublime.exe sublime_text.exe

Hope this helps!

PS..

If you are still using the regular windows command line window, think about trying out Console2, I have been using this utility for years and love it. Heard about it from Scott Hanselman over at hanselminutes.com and have never gone back. This allows you to resize the command line window, set the opacity and text color of the command line as well as lot’s of real cool stuff. Check it out!

Leave a Reply

You must be logged in to post a comment.