我如何使用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

当前回答

以下是Cygwin的解决方案:

#!/bin/dash -e
if [ "$1" ]
then k=$(cygpath -w "$1")
elif [ "$#" != 0 ]
then k=
fi
Notepad2 ${k+"$k"}

如果没有路径,则不传递路径 如果path为空,则传递空路径 如果path不为空,请转换为Windows格式。

然后我设置这些变量:

export EDITOR=notepad2.sh
export GIT_EDITOR='dash /usr/local/bin/notepad2.sh'

编辑器允许脚本与Git一起工作 GIT_EDITOR允许脚本使用Hub命令

其他回答

我正在使用Windows 10和notepad++,我得到了这个错误消息:

line 0: syntax error near unexpected token `(' git windows

所以我是这样做的:

git config --global core.editor 'C:/Program\ Files\ \(x86\)/Notepad++/notepad++.exe'

这是可行的

以下是Cygwin的解决方案:

#!/bin/dash -e
if [ "$1" ]
then k=$(cygpath -w "$1")
elif [ "$#" != 0 ]
then k=
fi
Notepad2 ${k+"$k"}

如果没有路径,则不传递路径 如果path为空,则传递空路径 如果path不为空,请转换为Windows格式。

然后我设置这些变量:

export EDITOR=notepad2.sh
export GIT_EDITOR='dash /usr/local/bin/notepad2.sh'

编辑器允许脚本与Git一起工作 GIT_EDITOR允许脚本使用Hub命令

更新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++命令行选项。

git config core.editor "\"C:\Program Files (x86)\Notepad++\notepad++.exe\""