我如何使用notepad++(或任何其他编辑器除了vim)与msysgit?

我尝试了以下所有方法,但都无济于事:

git config --global core.editor C:\Program Files\Notepad++\notepad++.exe

git config --global core.editor "C:\Program Files\Notepad++\notepad++.exe"

git config --global core.editor C:/Program Files/Notepad++/notepad++.exe

git config --global core.editor C:\\Program Files\\Notepad++\\notepad++.exe

当前回答

更新2010 - 2011:

Zumalifeguard的解决方案比原来的更简单,因为它不再需要外壳包装器脚本。

正如我在“如何在Windows上设置一个编辑器来使用Git ?”一文中所解释的那样,我更喜欢包装器,因为它更容易尝试和切换编辑器,或更改一个编辑器的路径,而不必再次用Git配置注册所做的更改。 但那只是我。


附加信息:以下解决方案适用于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脚本中的想法。 (正如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成为默认设置,你必须设置>Preferences> general >TabBar> Hide>uncheck每次你在rebase后启动记事本。这是地狱。你推荐了地狱。

所以用rather:

#!/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\…`,),你有三个选项:

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"'

其他回答

从Git for Windows v2.15.0(2017年10月30日)开始,现在可以将nano或notepad++配置为Git的默认编辑器,而不是vim。

在安装过程中,你会看到以下画面:

更新2015

如果你解包/安装notepad++到c:\utils\npp\并将notepad++.exe重命名为npp.exe,那么你所要做的就是

git config --global core.editor c:/utils/npp/npp.exe

没有包装器脚本或其他技巧。不需要在PATH中有notepad++。

按照这些说明,

首先确保你的系统上安装了notepad++,并且它是打开.txt文件的默认程序。 然后在您的系统上安装gitpad。请注意,我最后检查下载链接是坏的,所以下载从这里解释。

然后在提交时,你应该看到你最喜欢的文本编辑器弹出。

更新2010 - 2011:

Zumalifeguard的解决方案比原来的更简单,因为它不再需要外壳包装器脚本。

正如我在“如何在Windows上设置一个编辑器来使用Git ?”一文中所解释的那样,我更喜欢包装器,因为它更容易尝试和切换编辑器,或更改一个编辑器的路径,而不必再次用Git配置注册所做的更改。 但那只是我。


附加信息:以下解决方案适用于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脚本中的想法。 (正如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成为默认设置,你必须设置>Preferences> general >TabBar> Hide>uncheck每次你在rebase后启动记事本。这是地狱。你推荐了地狱。

所以用rather:

#!/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\…`,),你有三个选项:

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"'

我使用带有PATH变量的方法。notepad++的路径被添加到系统的Path变量中,然后是core。编辑器的设置如下:

git config --global core.editor notepad++

另外,你可以为notepad++添加一些额外的参数:

git config --global core.editor "notepad++.exe -multiInst"

(正如我在“Git核心”中详细描述的那样。Windows编辑器”)

在这里,你可以找到一些选项,你可以使用notepad++命令行选项。