2010-2011 年更新:
zumalifeguard 的solution(赞成)比原来的更简单,因为它不再需要 shell 包装脚本。
正如我在“How can I set up an editor to work with Git on Windows?”中解释的那样,我更喜欢包装器,因为它更容易尝试切换编辑器或更改一个编辑器的路径,而无需使用git config 注册所述更改再次。
但这只是我。
附加信息:以下解决方案适用于 Cygwin,而 zuamlifeguard 的解决方案不适用。
原始答案。
以下内容:
C:\prog\git>git config --global core.editor C:/prog/git/npp.sh
C:/prog/git/npp.sh:
#!/bin/sh
"c:/Program Files/Notepad++/notepad++.exe" -multiInst "$*"
确实有效。这些命令被解释为 shell 脚本,因此将任何 Windows 命令集包装在 sh 脚本中的想法。
(作为Frankycomments:“记得用Unix风格的行结尾保存你的.sh文件,否则会收到神秘的错误信息!”)
关于 SO 问题的更多细节How can I set up an editor to work with Git on Windows?
注意“-multiInst”选项,以确保每次来自 Git 的调用都有一个新的 notepad++ 实例。
还要注意,如果您在 Cygwin 上使用 Git(并且想use Notepad++ from Cygwin),那么scphantm 在“using Notepad++ for Git inside Cygwin”中说明您必须注意:
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 "$*")" 是这里的重要部分。
Valcommented(然后删除)你不应该使用-notabbar选项:
在变基期间禁用选项卡没有好处,但会对记事本的一般可用性造成很大损害,因为-notab 成为默认设置,并且每次在变基后启动记事本时都必须Settings>Preferences>General>TabBar> Hide>uncheck。这是地狱。你推荐了地狱。
所以宁可使用:
#!/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'
-
或试试shortname notation(不是万无一失的):
git config --global core.editor C:/progra~1/git/npp.sh
-
或者(我最喜欢的)将“npp.sh”放在%PATH% 环境变量的目录部分中。您不必为脚本指定任何路径。
git config --global core.editor npp.sh
-
Steiny 报告in the comments 不得不做:
git config --global core.editor '"C:/Program Files (x86)/Git/scripts/npp.sh"'