opening sublime text from windows git bash

2019-03-09 10:43发布

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.

10条回答
聊天终结者
2楼-- · 2019-03-09 11:10

Create .bash_profile file under C:\Users\YourUserName\ and add the following line in the file:

alias 'subl="/c/Program Files/Sublime Text 3/subl.exe"'
查看更多
放我归山
3楼-- · 2019-03-09 11:13

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.

I kept getting bash: subl: C:/Program command not found

or something like that

I 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.

I ended up typing

echo 'alias subl="C:/Program\ Files/Sublime\ Text\ 3/subl.exe"' >> ~/.bashrc

then subl

and sublime text was opened.

My original file path was-

C:\Program Files\Sublime Text 3

so 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.

I'm on windows 10 using sublime text 3 and git bash

Hopefully this saves someone else a lot of time.

查看更多
可以哭但决不认输i
4楼-- · 2019-03-09 11:17
  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. 32bit Copy it into the C:\Program Files\Git\usr\bin folder. 64bit

Now to open the file enter the following command on Windows Git Bash

subl text.txt

or

subl .
查看更多
何必那么认真
5楼-- · 2019-03-09 11:19

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:

alias subl='C:\\Program\ Files\\Sublime\ Text\ 3\\sublime_text.exe'
查看更多
成全新的幸福
6楼-- · 2019-03-09 11:21

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.

First I opened bash to my home directory, you can use cd~ to make sure you're in the right place.

Then, I created my .bashrc file using:

touch .bashrc

Then I went to edit that file using:

vim .bashrc

press the i key to enter insert mode

enter:

alias subl='C:/Program\ Files/Sublime\ Text\ 3/sublime_text.exe'

As 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.

now hit esc to exit input mode

Enter : w q enter to save and exit vim

exit bash and reopen to apply the new settings

Entering subl should open sublime text editor now.

I 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.

I 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.

Thanks for letting me revive an older post and I hope this helps.

查看更多
爱情/是我丢掉的垃圾
7楼-- · 2019-03-09 11:24

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).

Run the following command (based upon your requirement):

echo 'alias subl="/c/Program\ Files/Sublime\ Text\ 3/sublime_text.exe"'>> ~/.bashrc

Or

echo 'alias subl="/c/Program\ Files\ \(x86\)/Sublime\ Text\ 3/sublime_text.exe"'>> ~/.bashrc

Try Closing and Re-Opening Git-Bash. If it works, then you're done.
Otherwise, read this documentation from Udacity.

查看更多
登录 后发表回答