从 Windows git bash 打开 sublime 文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32282847/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
opening sublime text from windows git bash
提问by Pranay Aryal
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.
如何在 Windows 中从 Git Bash 打开 Sublime 文本?我尝试在 ~/.bashrc 文件中添加别名,但没有任何效果。我正在寻找一些非常简单的东西,但我在互联网上找不到。
回答by 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:
我要回答我自己的问题。首先,我.bash_profile
在 /Users/username 目录下创建了一个文件。我在这里复制了我所有的 git 别名。为了访问崇高的文本,我添加了这个别名:
alias subl="/c/Program\ Files/Sublime\ Text\ 2/sublime_text.exe"
I 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
我认为反斜杠后面的空格对于格式化很重要。如果这不起作用,您将不得不查看 sublime_text.exe 文件所在的位置,并在如上所述格式化后放置路径。现在在 git bash 命令行中输入
subl .
to open the current directory in Sublime Text or the name of the file as
在 Sublime Text 中打开当前目录或文件名
subl readme.md
to open it in Sublime Text. I also added other useful aliases in the .bash_profile
file like:
在 Sublime Text 中打开它。我还在.bash_profile
文件中添加了其他有用的别名,例如:
alias gc="git commit -m"
alias ga="git add ."
alias gl="git log"
alias gs="git status"
So in your git bash command prompt you can simply type
所以在你的 git bash 命令提示符下你可以简单地输入
gs ##for git status
gl ##for git log, etc
I hope this will help someone.
我希望这会帮助某人。
回答by Pkr
Create .bash_profile
file under C:\Users\YourUserName\
and add the following line in the file:
在下面创建.bash_profile
文件C:\Users\YourUserName\
并在文件中添加以下行:
alias 'subl="/c/Program Files/Sublime Text 3/subl.exe"'
回答by Ady
A Better Solution:
更好的解决方案:
The updated version of sublime text 3(Build 3065) brings this feature as "subl.exe" which was "subl" in mac os.
sublime text 3(Build 3065)的更新版本将此功能称为“subl.exe”,在mac os中为“subl”。
How to use:
如何使用:
step 1: Update sublime text (in sublimetext --> Help -> Check for Updates)
step 2: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)
第 1 步:更新 sublime 文本(在 sublimetext --> 帮助 -> 检查更新)
第 2 步:只需通过 bash 导航到您的项目文件夹并键入 subl.exe,这将在 sublime 文本中打开该文件夹。(如果您遇到找不到“subl.exe”命令,只需添加 sublime 的路径,例如:“C:\Program Files\Sublime Text 3”到您的系统路径 - 以下是添加环境变量路径的方法)
回答by 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.
我对这些东西以及 git 和 sublime text 都很陌生。我现在正在学习有关 git 的 Udacity 课程,但无法使用 git bash 打开 sublime text。
I kept getting bash: subl: C:/Program command not found
我不断收到 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
echo 'alias subl="C:/Program\ Files/Sublime\ Text\3/subl.exe"' >> ~/.bashrc
then subl
然后subl
and sublime text was opened.
并打开了崇高的文字。
My original file path was-
我的原始文件路径是-
C:\Program Files\Sublime Text 3
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
我在 Windows 10 上使用 sublime text 3 和 git bash
Hopefully this saves someone else a lot of time.
希望这可以为其他人节省很多时间。
回答by jtcotton63
I added this to my C:\Users\username\.bashrc file:
我将此添加到我的 C:\Users\username\.bashrc 文件中:
export PATH="$PATH:/c/Program Files/Sublime Text 3"
Save the file. Then in Git Bash, type
保存文件。然后在 Git Bash 中输入
which subl
to prove it works.
来证明它有效。
回答by Moiz Sajid
Create a text file called subl (with no extension) with the following content:
#!/bin/sh "C:\Program Files\Sublime Text 2\sublime_text.exe" &
Copy it into the C:\Program Files (x86)\Git\bin folder. 32bit Copy it into the C:\Program Files\Git\usr\bin folder. 64bit
创建一个名为 subl(无扩展名)的文本文件,内容如下:
#!/bin/sh "C:\Program Files\Sublime Text 2\sublime_text.exe" &
将其复制到 C:\Program Files (x86)\Git\bin 文件夹中。32bit 复制到 C:\Program Files\Git\usr\bin 文件夹中。64位
Now to open the file enter the following command on Windows Git Bash
现在打开文件在 Windows Git Bash 上输入以下命令
subl text.txt
or
或者
subl .
回答by Stephen Haruna
I had the same issue launching Sublime Text 3 form Git Bash.
我在从 Git Bash 启动 Sublime Text 3 时遇到了同样的问题。
I ran the following command (my OS was windows 7 and Sublime Text 3 was located in the "
C:\Program Files\Sublime Text 3
" directory) :echo 'alias subl="
/C/Program\ Files/Sublime\ Text\ 3/sublime_text.exe
"' >>~/.bashrc
Close Git Bash and Open it again.
- Type subl
我运行了以下命令(我的操作系统是 windows 7,而 Sublime Text 3 位于“
C:\Program Files\Sublime Text 3
”目录中):echo '别名 subl="
/C/Program\ Files/Sublime\ Text\ 3/sublime_text.exe
"' >>~/.bashrc
关闭 Git Bash 并再次打开它。
- 类型 subl
回答by Amitrajit Bose
Locate the folder where Sublime Text is installed. Here I'am taking an example of Sublime Text 3which is installed in C:/Program Files. For many users it is present in C:/Program Files (x86).
找到安装 Sublime Text 的文件夹。这里我以安装在C:/Program Files 中的 Sublime Text 3为例。对于许多用户来说,它存在于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.
尝试关闭并重新打开 Git-Bash。如果它有效,那么你就完成了。
否则,请从Udacity阅读此文档。
回答by 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:
我遇到的问题之一是我必须\
在目录路径中使用反斜杠而不是普通的斜杠/
,就像这里的每个人都在使用的那样。然后我不得不使用双反斜杠来逃避反斜杠\\
。所以,就我而言,我写了这样的路径:
alias subl='C:\Program\ Files\Sublime\ Text\ 3\sublime_text.exe'
回答by 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 herefixed the problem for me. I'm using Git bash on windows 10.
尽管这里列出了所有答案,但我也很难让它对我有用。我发现按照此处的建议通过 VIM 修改我的 .bashrc 文件为我解决了这个问题。我在 Windows 10 上使用 Git bash。
First I opened bash to my home directory, you can use cd~ to make sure you're in the right place.
首先我打开 bash 到我的主目录,你可以使用 cd~ 来确保你在正确的地方。
Then, I created my .bashrc file using:
然后,我使用以下命令创建了我的 .bashrc 文件:
touch .bashrc
touch .bashrc
Then I went to edit that file using:
然后我去编辑该文件使用:
vim .bashrc
press the i
key to enter insert mode
按i
键进入插入模式
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.
正如几乎所有人所指出的,这必须是您 sublime_text.exe 位置的正确路径。快速搜索 C:\ 驱动器中的 sublime_text.exe 应该会得到这个位置。
now hit esc
to exit input mode
现在点击esc
退出输入模式
Enter :
w
q
enter
to save and exit vim
回车:
w
q
enter
保存退出vim
exit bash and reopen to apply the new settings
退出 bash 并重新打开以应用新设置
Entering subl
should open sublime text editor now.
subl
现在输入应该打开 sublime text editor。
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.
我曾尝试用写字板和崇高的文本本身编辑我的 .bashrc 文件,但由于某种原因在 vim 中编辑并确保所有正斜杠和反斜杠都是正确的,如上所述对我有用。
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.
我使用其他一些方法在我的文件路径之后发现了一个流氓 ^M 字符,我认为这些方法也可能使事情变得复杂。在使用 SawyerDoesStuff 的解决方案后,在 vim 中删除这个字符也解决了这个问题。
Thanks for letting me revive an older post and I hope this helps.
感谢您让我恢复旧帖子,我希望这会有所帮助。