Home:ALL Converter>opening sublime text from windows git bash

opening sublime text from windows git bash

Ask Time:2015-08-29T12:56:16         Author:Pranay Aryal

Json Formatter

How do I open Sublime text from Git Bash in Windows? I tried adding the alias at the ~/.bashrc file but nothing worked. I was looking for something very easy but I could not find in the internet.

Author:Pranay Aryal,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/32282847/opening-sublime-text-from-windows-git-bash
Moiz Sajid :

\nCreate a text file called subl (with no extension) with the following content:\n\n#!/bin/sh\n\"C:\\Program Files\\Sublime Text 2\\sublime_text.exe\" $1 &\n\nCopy it into the C:\\Program Files (x86)\\Git\\bin folder. 32bit\nCopy it into the C:\\Program Files\\Git\\usr\\bin folder. 64bit\n\n\nNow to open the file enter the following command on Windows Git Bash\n\nsubl text.txt\n\n\nor\n\nsubl .\n",
2015-08-30T11:12:05
teuber789 :

I added this to my C:\\Users\\username\\.bashrc file:\n\nexport PATH=\"$PATH:/c/Program Files/Sublime Text 3\"\n\n\nSave the file. Then in Git Bash, type\n\nwhich subl\n\n\nto prove it works.",
2016-09-21T00:24:25
0xsteve :

I had the same issue launching Sublime Text 3 form Git Bash. \n\n\nI ran the following command (my OS was windows 7 and Sublime Text 3 was located in the \"C:\\Program Files\\Sublime Text 3\" directory) :\n\necho 'alias subl=\"/C/Program\\ Files/Sublime\\ Text\\ 3/sublime_text.exe\"' >> ~/.bashrc\nClose Git Bash and Open it again.\nType subl\n",
2017-08-11T08:44:24
Cristiano Ferro :

One of the problems I had was that I had to use backslashes \\ in the path of the directory instead of normal slashes /, like the everyone here is using. Then I had to escape backslashes using double backslash \\\\. So, in my case I wrote the path like this: \n\nalias subl='C:\\\\Program\\ Files\\\\Sublime\\ Text\\ 3\\\\sublime_text.exe'\n",
2018-06-26T13:06:29
wellthatdidn'twork :

I was having some difficulty getting this to work for me as well despite all the answers listed here. I found that modifying my .bashrc file through VIM as suggested here fixed the problem for me. I'm using Git bash on windows 10. \n\nFirst I opened bash to my home directory, you can use cd~ to make sure you're in the right place. \n\nThen, I created my .bashrc file using:\n\ntouch .bashrc\n\nThen I went to edit that file using:\n\nvim .bashrc\n\n\npress the i key to enter insert mode\n\nenter:\n\nalias subl='C:/Program\\ Files/Sublime\\ Text\\ 3/sublime_text.exe'\n\n\nAs noted by pretty much everyone else this will have to be the correct path to your sublime_text.exe location. A quick search of your C:\\ drive for sublime_text.exe should yield this location. \n\nnow hit esc to exit input mode\n\nEnter : w q enter to save and exit vim\n\nexit bash and reopen to apply the new settings\n\nEntering subl should open sublime text editor now.\n\nI had tried editing my .bashrc file with wordpad and sublime text itself, but for some reason editing in vim and making sure all the forward slashes and backslashes were correct as noted above worked for me. \n\nI had found a rogue ^M character after my file path using some of the other methods which I think might have been complicating things as well. deleting this character in vim also fixed the problem after using SawyerDoesStuff's solution.\n\nThanks for letting me revive an older post and I hope this helps.",
2017-04-15T20:55:16
Amitrajit Bose :

Locate the folder where Sublime Text is installed. Here I'am taking an example of Sublime Text 3 which is installed in C:/Program Files. For many users it is present in C:/Program Files (x86).\n\nRun the following command (based upon your requirement):\n\necho 'alias subl=\"/c/Program\\ Files/Sublime\\ Text\\ 3/sublime_text.exe\"'>> ~/.bashrc\n\n\nOr\n\necho 'alias subl=\"/c/Program\\ Files\\ \\(x86\\)/Sublime\\ Text\\ 3/sublime_text.exe\"'>> ~/.bashrc\n\n\nTry Closing and Re-Opening Git-Bash. If it works, then you're done. \nOtherwise, read this documentation from Udacity.",
2018-05-10T11:14:01
Pranay Aryal :

I am going to answer my own question. First, I created a .bash_profile file under /Users/username directory. I have copied all my git aliases here. To access sublime text I added this alias:\n\nalias subl=\"/c/Program\\ Files/Sublime\\ Text\\ 2/sublime_text.exe\"\n\n\nI think the spaces after the backward slashes are important for formatting. If this doesn't work you will have to look where your sublime_text.exe file situated at and put the path after formatting as above. Now in the git bash command line just type\n\nsubl . \n\n\nto open the current directory in Sublime Text or the name of the file as\n\nsubl readme.md\n\n\nto open it in Sublime Text. I also added other useful aliases in the .bash_profile file like:\n\nalias gc=\"git commit -m\"\nalias ga=\"git add .\"\nalias gl=\"git log\"\nalias gs=\"git status\"\n\n\nSo in your git bash command prompt you can simply type\n\ngs ##for git status\ngl ##for git log, etc\n\n\nI hope this will help someone.",
2015-08-29T05:03:12
tehDeveloper :

Create .bash_profile file under C:\\Users\\YourUserName\\ and add the following line in the file:\n\nalias 'subl=\"/c/Program Files/Sublime Text 3/subl.exe\"'\n",
2017-06-05T12:20:01
Ady :

A Better Solution:\n\nThe updated version of sublime text 3(Build 3065) brings this feature as \"subl.exe\" which was \"subl\" in mac os. \n\nHow to use:\n\nstep 1: Update sublime text (in sublimetext --> Help -> Check for Updates)\nstep 2: \n Just navigate to your project folder through bash and type subl.exe which should open the folder in sublime text. (if you encounter \"subl.exe\" command not found, just add sublime's path eg: \"C:\\Program Files\\Sublime Text 3\" to your system path - Here's how to add path to environment variables)",
2016-05-15T23:43:47
SawyerDoesStuff :

I'm pretty new to this stuff and to git and sublime text. I'm taking the Udacity course on git right now, and was unable to get git bash to open sublime text.\n\nI kept getting bash: subl: C:/Program command not found\n\nor something like that\n\nI found my problem ended up being I had my slashes going the incorrect way, and I found if you have spaces in your file path, you have to add a slash everytime you have a space and it will fix the problem.\n\nI ended up typing\n\necho 'alias subl=\"C:/Program\\ Files/Sublime\\ Text\\ 3/subl.exe\"' >> ~/.bashrc\n\nthen subl\n\nand sublime text was opened.\n\nMy original file path was-\n\nC:\\Program Files\\Sublime Text 3\n\nso make sure you have your slashes going the correct way, and if you have spaces in your file path, to add the necessary slash after a word.\n\nI'm on windows 10\nusing sublime text 3\nand git bash\n\nHopefully this saves someone else a lot of time.",
2016-12-18T09:51:35
yy