如何在 msysgit 中使用 Notepad++(或其他)? [英] How do I use Notepad++ (or other) with msysgit?
问题描述
如何在 msysgit 中使用 Notepad++(或除 vim 之外的任何其他编辑器)?
我尝试了以下所有方法均无济于事:
git config --global core.editor C:Program FilesNotepad++
otepad++.exegit config --global core.editor "C:Program FilesNotepad++
otepad++.exe"git config --global core.editor C:/Program Files/Notepad++/notepad++.exegit config --global core.editor C:\Program Files\Notepad++\notepad++.exe
2010-2011 更新:
zumalifeguard 的 解决方案(已投票)比原始解决方案更简单,因为它不再需要 shell 包装脚本.
正如我在如何设置编辑器以在 Windows 上使用 Git?"中所述,我更喜欢包装器,因为它更容易尝试和切换编辑器,或更改一个编辑器的路径,而无需再次使用 git config
注册所述更改.
但这只是我.
附加信息:以下解决方案适用于 Cygwin,而 zuamlifeguard 的解决方案不适用.
<小时>原始答案.
以下内容:
C:proggit>git config --global core.editor C:/prog/git/npp.shC:/prog/git/npp.sh:#!/bin/sh"c:/Program Files/Notepad++/notepad++.exe" -multiInst "$*"
确实有效.这些命令被解释为 shell 脚本,因此可以将任何 Windows 命令集包装在 sh
脚本中.
(作为 Franky 评论:记得用Unix风格的行结尾保存你的.sh
文件,否则会收到神秘的错误信息!")
有关 SO 问题的更多详细信息 如何设置编辑器以在 Windows 上使用 Git?
注意 '-multiInst
' 选项,以确保每次来自 Git 的调用都有一个新的 notepad++ 实例.
另请注意,如果您在 Cygwin 上使用 Git(并且想要使用来自 Cygwin 的 Notepad++),然后 scphantm 在在 Cygwin 中使用 Notepad++ for Git"中解释说,您必须注意:
<块引用>git
正在向它传递一个 cygwin
路径,而 npp
不知道如何处理它
所以在这种情况下的脚本将是:
#!/bin/sh"C:/Program Files (x86)/Notepad++/notepad++.exe" -multiInst -notabbar -nosession -noPlugin "$(cygpath -w "$*")"
多行以提高可读性:
#!/bin/sh"C:/Program Files (x86)/Notepad++/notepad++.exe" -multiInst -notabbar -nosession -noPlugin "$(cygpath -w "$*")"
"$(cygpath -w "$*")"
是这里的重要部分.
Val 评论(然后删除)你不应该使用 -notabbar
选项:><块引用>
在 rebase 期间禁用选项卡没有好处,但会对一般记事本的可用性造成很大危害,因为 -notab
成为默认设置,您必须 Settings>Preferences>General>标签栏>每次在 rebase 后启动记事本时,隐藏>取消选中
.这是地狱.你推荐了地狱.
所以使用:
#!/bin/sh"C:/Program Files (x86)/Notepad++/notepad++.exe" -multiInst -nosession -noPlugin "$(cygpath -w "$*")"
即:
#!/bin/sh"C:/Program Files (x86)/Notepad++/notepad++.exe" -multiInst -nosession -noPlugin "$(cygpath -w "$*")"
<小时>
如果您想将脚本 'npp.sh
' 放在带有空格的路径中(如'c:program files...
',),你有三个选项:
尝试引用路径(单引号或双引号),例如:
git config --global core.editor 'C:/program files/git/npp.sh'
或尝试短名称表示法(并非万无一失):
git config --global core.editor C:/progra~1/git/npp.sh
或(我最喜欢的)将 '
npp.sh
' 放在%PATH%
环境变量的目录部分.这样您就不必为脚本指定任何路径.git config --global core.editor npp.sh
git config --global core.editor '"C:/Program Files (x86)/Git/scripts/npp.sh"'
How do I use Notepad++ (or any other editor besides vim) with msysgit?
I tried all of the following to no avail:
git config --global core.editor C:Program FilesNotepad++
otepad++.exe
git config --global core.editor "C:Program FilesNotepad++
otepad++.exe"
git config --global core.editor C:/Program Files/Notepad++/notepad++.exe
git config --global core.editor C:\Program Files\Notepad++\notepad++.exe
Update 2010-2011:
zumalifeguard's solution (upvoted) is simpler than the original one, as it doesn't need anymore a shell wrapper script.
As I explain in "How can I set up an editor to work with Git on Windows?", I prefer a wrapper, as it is easier to try and switch editors, or change the path of one editor, without having to register said change with a git config
again.
But that is just me.
Additional information: the following solution works with Cygwin, while the zuamlifeguard's solution does not.
Original answer.
The following:
C:proggit>git config --global core.editor C:/prog/git/npp.sh
C:/prog/git/npp.sh:
#!/bin/sh
"c:/Program Files/Notepad++/notepad++.exe" -multiInst "$*"
does work. Those commands are interpreted as shell script, hence the idea to wrap any windows set of commands in a sh
script.
(As Franky comments: "Remember to save your .sh
file with Unix style line endings or receive mysterious error messages!")
More details on the SO question How can I set up an editor to work with Git on Windows?
Note the '-multiInst
' option, for ensuring a new instance of notepad++ for each call from Git.
Note also that, if you are using Git on Cygwin (and want to use Notepad++ from Cygwin), then scphantm explains in "using Notepad++ for Git inside Cygwin" that you must be aware that:
git
is passing it acygwin
path andnpp
doesn't know what to do with it
So the script in that case would be:
#!/bin/sh
"C:/Program Files (x86)/Notepad++/notepad++.exe" -multiInst -notabbar -nosession -noPlugin "$(cygpath -w "$*")"
Multiple lines for readability:
#!/bin/sh
"C:/Program Files (x86)/Notepad++/notepad++.exe" -multiInst -notabbar
-nosession -noPlugin "$(cygpath -w "$*")"
With "$(cygpath -w "$*")"
being the important part here.
Val commented (and then deleted) that you should not use -notabbar
option:
It makes no good to disable the tab during rebase, but makes a lot of harm to general Notepad usability since
-notab
becomes the default setting and you mustSettings>Preferences>General>TabBar> Hide>uncheck
every time you start notepad after rebase. This is hell. You recommended the hell.
So use rather:
#!/bin/sh
"C:/Program Files (x86)/Notepad++/notepad++.exe" -multiInst -nosession -noPlugin "$(cygpath -w "$*")"
That is:
#!/bin/sh
"C:/Program Files (x86)/Notepad++/notepad++.exe" -multiInst -nosession
-noPlugin "$(cygpath -w "$*")"
If you want to place the script 'npp.sh
' in a path with spaces (as in
'c:program files...
',), you have three options:
Either try to quote the path (single or double quotes), as in:
git config --global core.editor 'C:/program files/git/npp.sh'
or try the shortname notation (not fool-proofed):
git config --global core.editor C:/progra~1/git/npp.sh
or (my favorite) place '
npp.sh
' in a directory part of your%PATH%
environment variable. You would not have then to specify any path for the script.git config --global core.editor npp.sh
Steiny reports in the comments having to do:
git config --global core.editor '"C:/Program Files (x86)/Git/scripts/npp.sh"'
这篇关于如何在 msysgit 中使用 Notepad++(或其他)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!