如何使 Sublime Text 成为 Git 的默认编辑器?
我在使用 git
将 Sublime Text 2 设置为 core.editor
时遇到问题。
我已经阅读了我能找到的所有解决该问题的帖子,但仍然没有任何效果。我正在运行Windows。
我已经完成了:
git config --global core.editor "'C:/Program Files/Sublime Text 2/sublime_text.exe'"
并尝试使用 -m
等各种参数。当我打开 .gitconfig
时,里面的内容如下:
[user]
name = Spencer Moran
email = [email protected]
[core]
editor = 'C:/Program Files/Sublime Text 2/sublime_text.exe'
如果我转到 Git 并输入:
README.markdown --edit
README 文件会在记事本中打开,而不是 Sublime Text。
有谁知道我做错了什么或者我该如何解决这个问题?
I have a problem setting Sublime Text 2 as the core.editor
with git
.
I've read through every post I could find addressing the problem, but still nothing is working for me. I am running Windows.
I have done:
git config --global core.editor "'C:/Program Files/Sublime Text 2/sublime_text.exe'"
and tried that with various arguments like -m
. When I open my .gitconfig
, this is what is in there:
[user]
name = Spencer Moran
email = [email protected]
[core]
editor = 'C:/Program Files/Sublime Text 2/sublime_text.exe'
If I go to Git and type:
README.markdown --edit
the README file opens in Notepad, not Sublime Text.
Does anyone have any idea what I'm doing wrong or how I could fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(18)
Windows
Sublime Text 2(内部版本 2181)
最新的内部版本 2181 刚刚添加了对
-w
(等待)命令行参数的支持。以下配置将允许 ST2 作为 Windows 上的默认 git 编辑器。这将允许 git 打开 ST2 以获取提交消息等。Sublime Text 3(内部版本 3065)
Sublime Text 3(内部版本 3065)添加了
subl.exe< /code> 命令行助手。使用
subl.exe -h
作为可用的选项。我在 Sublime Text 用户设置中设置了hot_exit: true
和remember_open_files: true
。我发现以下 git config 对我来说效果很好。Mac 和 Linux
通过在终端中键入以下命令将 Sublime 设置为 Git 编辑器:
git config --global core.editor "subl -n -w"
使用此 Git 配置,新选项卡为在我的编辑器中打开。我编辑提交消息,保存选项卡 (Ctrl+S) 并关闭它 (Ctrl+W) 。
Git 将等到选项卡关闭后再继续工作。
Windows
Sublime Text 2 (Build 2181)
The latest Build 2181 just added support for the
-w
(wait) command line argument. The following configuration will allow ST2 to work as your default git editor on Windows. This will allow git to open ST2 for commit messages and such.Sublime Text 3 (Build 3065)
Sublime Text 3 (Build 3065) added the
subl.exe
command line helper. Usesubl.exe -h
for the options available to you. I havehot_exit: true
andremember_open_files: true
set in my Sublime Text user settings. I have found the following to git config to work well for me.Mac and Linux
Set Sublime as your editor for Git by typing the following command in the terminal:
git config --global core.editor "subl -n -w"
With this Git config, the new tab is opened in my editor. I edit my commit message, save the tab (Ctrl+S) and close it (Ctrl+W).
Git will wait until the tab is closed to continue its work.
您可以在 Mac 和 Linux 上使用此命令:
You can use this command on Mac and Linux:
对于Mac和Sublime Text 3:
如果
git config --global core.editor "subl -n -w"
不起作用,请使用此git config
命令:注意:它不包含转义反斜杠。
For Mac & Sublime Text 3:
If
git config --global core.editor "subl -n -w"
doesn't work, use thisgit config
command:Note: it does not contain escaping backslashes.
对于 Mac OS X,在 [core] 下的 ~/.gitconfig 文件中,我必须放置此代码来解决我的问题。
这是 subl 工作正常但 git 无法访问它的时候。并显示这些错误
For Mac OS X in the file ~/.gitconfig under [core] I had to put this code to solve the issue on my end.
This was when subl was working fine but git was unable to access it. And was displaying these errors
在 cygwin/zsh 中对我有用的:
在 /usr/local/bin 中在 gitconfig 中创建 subl_git 文件
:
what worked for me in cygwin/zsh:
in /usr/local/bin create subl_git file
in gitconfig:
使用 Sublime Text 2 和以下配置,如果关闭 git commit 的注释文件时没有任何反应:
如果在 Sublime 中关闭 COMMIT_EDITMSG 注释文件时 git 提交没有完成,我发现这可能是因为您正在管理员模式下运行 CMD(并且已经在非管理员模式下打开了 Sublime Text)。我遇到了同样的问题,当我在正常模式下启动我的CMD时,它对我有用。
Ps:只是想回答@david在接受的答案中指出的问题评论,但我无法发表评论,因为我是新来的......所以我做了一个新的答案,因为我认为这对遇到问题的一些人来说可能有用。
With Sublime Text 2 and the following configuration, if nothing happens when you close the git commit's comment file :
If the git commit doesn't finish when you close the COMMIT_EDITMSG comment file in Sublime, I've found this is probably because you are running CMD in administrator mode (and have a Sublime Text already opened in non admin mode). I had the same problem and it worked for me when I started my CMD in normal mode.
Ps : just wanted to answer to the problem @david pointed out in the accepted answer's comments, but I couldn't post comment since I'm new here... so I've made a new answer, because I think this can be useful to some people encountering the problem.
我刚刚在 PowerShell(Windows 命令行工具,也可用作 GithubforWindows 上的默认命令行)的帮助下成功完成了它,
只需在“C:\Users\%username%\My Documents”上创建一个文件夹“WindowsPowerShell” ”。
然后,创建一个名为“profile.ps1”的文件。
确保您的文件扩展名正确,是 .ps1 而不是 .txt。
在 profile.ps1 中,输入以下行来设置别名命令:
确保计算机上的 sublime 目录是正确的。
您还可以在此处查看配置详细信息。
现在,我可以通过 PowerShell 命令使用 Sublime Text 2 编辑文件,只需键入:
希望这有用...
I just successfully made it with the help of PowerShell (command line tools for windows, which is also be use as the default command line on GithubforWindows)
Just make a folder "WindowsPowerShell" on "C:\Users\%username%\My Documents".
Then, create a file called "profile.ps1".
Make sure that you have the correct file extension, .ps1 and not .txt.
inside the profile.ps1, put this line to set an alias command:
Make sure the sublime directory on your machine is correct.
You can also see the configuration details in here.
Now, I can edit files with Sublime Text 2 via PowerShell command just by typing:
Hopefully this is usefull...
今天晚上我在 Windows 中的 git 编辑器中遇到了同样的问题,终于解决了。
您需要使用 bash 语法并使用 DOS 8.3 格式来设置编辑器路径以避免空格:
这不起作用(对我来说):
这样做:
您可以获得 DOS 8.3 名称对于带有 dir /x 的目录
I've faced the same problem with git editor in Windows this evening, and finally I've got it.
You'll need to set your editor path with the bash syntax and using the DOS 8.3 format to avoid spaces:
This doesn't work (for me):
This do:
You can get the DOS 8.3 name for a directory with dir /x
在 MacOS(Mojave) 上,下面的内容适用于 Sublime 3:
git config --global core.editor "/Applications/Sublime\ Text.app/Contents /SharedSupport/bin/subl -n -w"
On MacOS(Mojave) below is working for me for Sublime 3:
git config --global core.editor "/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl -n -w"
对于 Windows,请尝试此操作
For Windows, try this
由于某种原因,我只是在努力解决这个问题,上面的例子都不适合我。然而,这是我的解决方案:
您特别需要路径周围的
'
和参数末尾的$*
,所有这些都在" "
。I was just struggling with this for some reason, none of the examples above quite worked for me. This was my solution however:
You specifically need the
' '
around the path and the$*
at the end of the args, all in" "
.如果您是 Mac 用户,请按以下步骤操作:
If you are Mac User, then here is how:
好吧,即使将其设置为我的 core.editor 后,我在从 gitbash 调用 notepad++ 时也遇到了一些问题。
我通过将以下行附加到 gitbash 安装目录中的 .bashrc 文件中来解决所有问题。
所以,我可以使用别名“npp”调用notepad++。我觉得如果您将目录更改为您想要使用的相应编辑器,这可以帮助您。
well, i had some trouble invoking notepad++ from gitbash even after setting it as my core.editor.
i got it all solved by appending the below line to my .bashrc file in my gitbash installation directory.
so, i can invoke notepad++ with the alias "npp". i feel this can help you if you change the directory to the respective editor you want to use.
对于 MAC 用户,我可以说 Sublime 使用以下命令:
首先使用命令检查 .gitconfig 文件:
cd ~
ls -la
cat .gitconfig
现在可以添加此配置:
其中
l1
将告诉从第 1 行开始。For MAC Users I can say for Sublime use the following:
First Check the .gitconfig file using command:
cd ~
ls -la
cat .gitconfig
Now one can add this configuration:
Where
l1
will tell to start at line 1.在 Windows 上,如果您正在安装 git,您可以选择其他编辑器并输入以下命令行。
C:\Program Files\Sublime Text 3\sublime_text.exe -w
On Windows, if you are installing git, you can select other editor and give the following command line.
C:\Program Files\Sublime Text 3\sublime_text.exe -w
对于 Windows 7,我发现以下解决方案有效:
For Windows 7 I have found the following solution works:
我还没有看到任何关于 Windows 的更新实例,允许 Git 安装主动选择 Sublime Text 作为默认文本编辑器,而无需原始覆盖代码的所有猛烈攻击......
I haven't seen any instances of updates regarding Windows allowing Git installation to actively pick Sublime Text as your default text editor without all the sturm und drang of the original override codes...
对于 Windows 10 和 Sublime Text 4
您可以仔细编辑
.gitconfig
如下:将行编辑器行编辑到此路径,以便 git 可以找到 subl 4。
需要双字符
\\
来转义反斜杠字符。.gitconfig
文件位于您的根配置文件目录中,例如:C:\Users\YourUsername\.gitconfig
For Windows 10 with sublime text 4
You can carefully edit your
.gitconfig
to this:Edit the line editor line to this path so git can find subl 4.
The doble
\\
Are needed for escape the backslash character.The
.gitconfig
file is found on your Root profile directory eg:C:\Users\YourUsername\.gitconfig