I wrote a post about how to open NotePad++ from the bash prompt a few years ago but I recently made the switch to using Sublime Text 2 as my standard text editor and had to figure out how to do the same thing with Sublime. It was surprisingly difficult to find it on Google.
1. Create a text file called subl (with no extension) with the following content:
#!/bin/sh "C:\Program Files\Sublime Text 2\sublime_text.exe" $1 &
2. copy it into the C:\Program Files (x86)\Git\bin folder.
The first line indicates that this is a shell script. The first part of the second line is the path to the Sublime exe. The $1 parameter passes in any parameters so that you can use it like this from the bash prompt (command line) to open a file:
subl text.txt
or
subl .
to open the current folder.
The last parameter & indicates that it should open Sublime in the background so that you can continue using the command prompt.
Thanks, I appreciate the time you took to document this.
Thank you so much for sharing this tip. Works great, now I can simple open files with Git Bash with ease. :)
Great! Though make sure sublime isn’t configured to “Run as administrator”, otherwise you’ll get the error “Bad file number” when running subl.
Thank you so much for posting this! I was bashing my head against a wall trying to get this to work with a doskey but this solution is much simpler! :)
Great tip! I also make a subl.bat in my home directory with `@CALL “C:\Program Files\Sublime Text 2\sublime_text.exe” %*`
Thanks for sharing this tip! it helped me a lot!
Reblogged this on PareidoliaX and commented:
I found lots of ways to setup sublime text 2 in Git Bash online, but this is by far the quickest and easiest.
Thanks a ton!! Worked. Helped A LOT.
I’m learning from scratch via youtube and other resources. this was extremely helpful. thank you so much. i love the internet.
i am getting an error “sh.exe”: subl: command not found” .
Kindly help
PANKAJ, go to the location where you created the subl.txt file. Then right-click, rename, and remove the .txt. It will give you an error stating the file will be unreadable. Once you do this open git command line again and type subl . you should then see the sublime text editor open. Hope that helps
I’m getting the same thing, yet there is no .txt I made it specifically that way. Could you pleas help?
See this post if you’re on Windows 7: https://danlimerick.wordpress.com/2011/06/10/git-for-windows-tip-setting-shell-aliases-with-msysgit/
Basically add an extra full stop at the end and Windows will automatically strip it off:
e.g. subl. becomes subl
hi michael, i still receive the same error as pankaj every after the fix. Can you pls help?
hi michael, i still receive the same error as pankaj every after the fix. Can you pls help?
I got the same problem. I an on windows, but can’t seem to get the .text extension of…
See this post if you’re on Windows 7: https://danlimerick.wordpress.com/2011/06/10/git-for-windows-tip-setting-shell-aliases-with-msysgit/
Basically add an extra full stop at the end and Windows will automatically strip it off:
e.g. subl. becomes subl
Great! Thanks.
I had the same issue. I’m running Windows 10. I had to place my file in C:\Program Files\Git\cmd
Worked.
Worked for me as well, thanks!
Victor thank you!! You saved me with this!
Thanks, it worked for me too, after I’ve been struggling like an hour. It would be great to patch the initial post, to add your findings in it
Thank you! that’s because in newer versions the ‘cmd’ folder is part of the path, while the ‘bin’ one is not
This worked for me! TY
In cmd folder if works for me, thanks
YOU SAVED MY SANITY! THANK YOU SO MUCH!
With 64bit git I had to place in C:\Program Files\Git\usr\bin
Thanks a million :D
+1, check any shell location with `echo $SHELL`.
Thanks a lot, man, worked just fine for me
I am using windows 10 and I have done everything as told. Also I have even pasted the subl file to all the directories mentioned in the comments but still get :command not found”
@Ivan (and anyone else having issues in Windows 10) – I was having the same issue, and was able to resolve through a combination of peoples comments in this thread. The problem is that ‘C:\Program Files (x86)\Git\bin’ wasn’t where my git bash was actually launching from, so it makes sense that it had no idea what ‘subl’ was. I will attempt to detail how to resolve this issue:
– First, launch your git bash client and type ‘explorer.exe .’
– Assuming you haven’t modified the path which git defaults to on launch, this will open your home directory in Windows Explorer. This will be the starting path for where you will add the ‘subl’ file.
(NOTE: if you have modified your start path, just type ‘cd /’ and that should bring you to the home directory, then start from the first step again)
– In the instructions from this post, it tells you to add the ‘subl’ file to ‘C:\Program Files (x86)\Git\bin’, but it should in fact be added to ‘[path from above]\usr\bin’.
For me, it was ‘C:\Users\[userFolder]\AppData\Local\Programs\Git\bin’
– Once I placed the ‘subl’ file in that directory, I was able to launch programs with sublime text as described!
Hope this helps someone!
TK
Anyone who has recently downloaded Sublime will need to change the path in the copied text to reflect the correct verion (Version 3) instead of the stated version (Version 2). Otherwise the bin file will not have a legitimate path to Sublime.
More smart: create a file .bash_profile in your home dir with content: alias subl='”C:\Program Files\Sublime Text 2\sublime_text.exe” $1 &’
Ah, some content correction: alias subl=’/c/Program\ Files/Sublime\ Text\ 2/sublime_text.exe –multiinstance’
Now that works. Also I have added to run the editor in “–multiinstance” mode. If you do not like it – remove. But I do :)
Thank you! This works great.
For those of you who are getting the ‘bash: subl: command not found’ error:
Try to save the file with ” ” around the file name. Also, place it in the Git/cmd directory.
Hope this helps :)