Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save placidrod/d67cc35c34f034ec5964e8adcac21f6f to your computer and use it in GitHub Desktop.
Save placidrod/d67cc35c34f034ec5964e8adcac21f6f to your computer and use it in GitHub Desktop.
Sublime Text 3 - Open in Command Line (Windows)
You can open sublime text from command line with subl.exe and subl. The second one has a problem. If sublime text is not open already,
when you open sublime text with subl, the command prompt will wait until sublime text is closed. So, you cannot do anything else in
terminal, unless you open another terminal. This is useful in some cases. But sometimes its a pain.
Method 1: Open with subl.exe
1. Go to Control Panel > Advanced System Settings -> Advanced -> Environment Variables
2. Create a new system variable called SUBLIME that will point to the folder of your Sublime installation.
Variable Name: SUBLIME
Variable Value: C:\Program Files\Sublime Text 3
3. Edit User variables Path
At the end of the existing text in the Variable value, add a semicolon and %SUBLIME%
4. If terminal is open, restart it and execute subl.exe
5. It will open sublime text
Note 1:
1. Executing subl.exe will open sublime text
2. Executing subl.exe . will open the current directoy with sublime text
3. Executing subl.exe filename will open the file with filename with sublime text
Note 2:
You will notice that the command prompt will not wait for sublime text to close
Method 2: Open with subl (in Git bash)
1. Go to home directory using cd ~
2. Create a .bash_profile using touch .bash_profile
3. Insert the following text in .bash_profile and save:
test -f ~/.profile && . ~/.profile
test -f ~/.bashrc && . ~/.bashrc
4. Create a .bashrc using touch .bashrc
5. Insert the following text in .bashrc and save:
alias subl="C:/Program\ Files/Sublime\ Text\ 3/sublime_text.exe"
6. Restart git bash and close sublime text if it is open
7. Execute subl
8. It will open sublime text
Note 1:
1. Executing subl will open sublime text
2. Executing subl . will open the current directoy with sublime text
3. Executing subl filename will open the file with filename with sublime text
Note 2:
If the sublime text is not open before you execute the above commands, You will notice that the command prompt will wait
for sublime text to close.
@chabinot
Copy link

It works, but what i want is to open sublime like that:
C:\wamp\www\folder, then subl must been opened with the folder,
I do C:\wamp\www and subl folder and that's working.
Have you an idea how to do ?

@nyoman
Copy link

nyoman commented Feb 6, 2018

Method 1 can be done with ease like this:

  1. Systems > Advance system settings > Environment Variables > System variables > Edit > New > C:\Program Files\Sublime Text 3
  2. Click all OKs or OK > OK > OK
  3. To open Sublime Text 3: Open a new Command Line > subl.exe or just subl.
  4. Open the current directoy with sublime text: Open a new command (example: E:\rails\projects) > subl.exe . or subl .

@JoseFMP
Copy link

JoseFMP commented Sep 14, 2018

Method 2 not working. When typing subl in the bash, it is available. But git will claim command not found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment