git 如何在 msysgit 中使用 Notepad++(或其他)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1634161/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I use Notepad++ (or other) with msysgit?
提问by PHLAK
How do I use Notepad++ (or any other editor besides vim) with msysgit?
如何在 msysgit 中使用 Notepad++(或除 vim 之外的任何其他编辑器)?
I tried all of the following to no avail:
我尝试了以下所有方法都无济于事:
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
采纳答案by VonC
Update 2010-2011:
2010-2011 年更新:
zumalifeguard's solution(upvoted) is simpler than the original one, as it doesn't need anymore a shell wrapper script.
zumalifeguard的解决方案(已投票)比原始解决方案更简单,因为它不再需要 shell 包装器脚本。
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.
正如我在“如何设置编辑器以在 Windows 上使用 Git?”中所述,我更喜欢包装器,因为尝试切换编辑器或更改一个编辑器的路径更容易,而无需注册所述更改有git config
一次。
但是,这只是我。
Additional information: the following solution works with Cygwin, while the zuamlifeguard's solution does not.
附加信息:以下解决方案适用于Cygwin,而 zuamlifeguard 的解决方案则不适用。
Original answer.
原答案。
The following:
下列:
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 "$*"
does work. Those commands are interpreted as shell script, hence the idea to wrap any windows set of commands in a sh
script.
(As Frankycomments: "Remember to save your .sh
file with Unix style line endings or receive mysterious error messages!")
确实有效。这些命令被解释为 shell 脚本,因此将任何 Windows 命令集包装在sh
脚本中的想法。
(正如Franky评论的那样:“记住.sh
用 Unix 风格的行结尾保存你的文件,否则会收到神秘的错误信息!”)
More details on the SO question How can I set up an editor to work with Git on Windows?
有关 SO 问题的更多详细信息如何设置编辑器以在 Windows 上使用 Git?
Note the '-multiInst
' option, for ensuring a new instance of notepad++ for each call from Git.
注意 ' -multiInst
' 选项,以确保每次来自 Git 的调用都有一个新的 notepad++ 实例。
Note also that, if you are using Git on Cygwin(and want to use Notepad++ from Cygwin), then scphantmexplains in "using Notepad++ for Git inside Cygwin" that you must be aware that:
另请注意,如果您在Cygwin上使用 Git (并且想使用 Cygwin 的 Notepad++),那么scphantm在“在 Cygwin 中使用 Notepad++ for Git”中解释说,您必须注意:
git
is passing it acygwin
path andnpp
doesn't know what to do with it
git
正在传递一条cygwin
路径,npp
但不知道如何处理它
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.
随着"$(cygpath -w "$*")"
来这里的重要组成部分。
Valcommented(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.
在 rebase 期间禁用选项卡没有好处,但会对一般记事本的可用性造成很大伤害,因为它
-notab
成为默认设置,并且Settings>Preferences>General>TabBar> Hide>uncheck
每次在 rebase 后启动记事本时都必须这样做。这是地狱。你推荐了地狱。
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:
如果您想将脚本 ' 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
Steinyreports in the commentshaving to do:
git config --global core.editor '"C:/Program Files (x86)/Git/scripts/npp.sh"'
尝试引用路径(单引号或双引号),如下所示:
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"'
回答by zumalifeguard
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
Or, for 64-bit Windows and a 32-bit install of Notepad++:
或者,对于 64 位 Windows 和 Notepad++ 的 32 位安装:
git config --global core.editor "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
Or, the following can be issued on the command line on either 32-bit or 64-bit Windows. It will pull the location of notepad++.exe from the registry and configure git to use it automatically:
或者,可以在 32 位或 64 位 Windows 上的命令行上发出以下命令。它将从注册表中提取 notepad++.exe 的位置并配置 git 以自动使用它:
FOR /F "usebackq tokens=2*" %A IN (`REG QUERY "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths\notepad++.exe" /ve`) DO git config --global core.editor "'%B' -multiInst -notabbar -nosession -noPlugin"
If you wish to place the above from a .BAT or .CMD file, you must replace %A with %%A and %B with %%B
如果您希望从 .BAT 或 .CMD 文件中放置上述内容,则必须将 %A 替换为 %%A,将 %B 替换为 %%B
回答by Tim Scott
This works for me
这对我有用
git config --global core.editor C:/Progra~1/Notepad++/notepad++.exe
回答by Jus
git config core.editor "\"C:\Program Files (x86)\Notepad++\notepad++.exe\""
回答by AXO
As of Git for Windows v2.15.0 (October 30th 2017)it is now possible to configure nano
or Notepad++as Git's default editor instead of vim
.
从Git for Windows v2.15.0(2017 年 10 月 30 日)开始,现在可以将或Notepad++配置nano
为 Git 的默认编辑器而不是.vim
During the installation you'll see the following screen:
在安装过程中,您将看到以下屏幕:
回答by starikovs
I use the approach with PATH variable. Path to Notepad++ is added to system's PATH variable and then core.editor is set like following:
我使用 PATH 变量的方法。Notepad++ 的路径被添加到系统的 PATH 变量中,然后 core.editor 设置如下:
git config --global core.editor notepad++
Also, you may add some additional parameters for Notepad++:
此外,您可以为 Notepad++ 添加一些额外的参数:
git config --global core.editor "notepad++.exe -multiInst"
(as I detailed in "Git core.editor
for Windows")
(正如我在“ Git core.editor
for Windows”中详述的那样)
And here you can find some options you may use when stating Notepad++ Command Line Options.
在这里您可以找到一些在说明 Notepad++ Command Line Options时可能使用的选项。
回答by Dan Dascalescu
UPDATE 2015
2015 年更新
If you unpack/install Notepad++ into c:\utils\npp\
and rename notepad++.exe to npp.exe for simplicity, then all you have to do is
如果您将 Notepad++ 解压/安装到其中c:\utils\npp\
并为简单起见将 notepad++.exe 重命名为 npp.exe,那么您所要做的就是
git config --global core.editor c:/utils/npp/npp.exe
No wrapper scripts or other trickery. No need to have Notepad++ in PATH.
没有包装脚本或其他技巧。无需在 PATH 中安装 Notepad++。
回答by Juan Luis Vivas Occhipinti
I am using Windows 10 and notepad++, and I was getting this error message:
我正在使用 Windows 10 和记事本++,但收到此错误消息:
line 0: syntax error near unexpected token `(' git windows
So I make the setup in this way:
所以我以这种方式进行设置:
git config --global core.editor 'C:/Program\ Files\ \(x86\)/Notepad++/notepad++.exe'
and it works
它有效
回答by Aditya P
Follow these instructions,
按照这些说明,
First make sure you have notepad++installed on your system and that it is the default programme to open .txt files.
Then Install gitpadon your system. Note the last I checked the download link was broken, so download it from hereas explained.
Then while committing you should see your favorite text editor popping up.
然后在提交时,您应该会看到您最喜欢的文本编辑器弹出。
回答by Ivan
I used starikovs' solution. I started with a bash window and gave the commands
我使用了starikovs的解决方案。我从一个 bash 窗口开始并给出了命令
cd ~
touch .bashrc
Then I found the .bashrc file in windows explorer, opened it with notepad++ and added
然后我在windows资源管理器中找到.bashrc文件,用notepad++打开并添加
PATH=$PATH:"C:\Program Files (x86)\Notepad++"
so that bash knows where to find Notepad++. (Having Notepad++ in the bash PATH is a useful thing on its own!) Then I pasted his line
这样 bash 就知道在哪里可以找到 Notepad++。(在 bash PATH 中使用 Notepad++ 本身就是一个有用的东西!)然后我粘贴了他的行
git config --global core.editor "notepad++.exe -multiInst"
into a bash window. I started a new bash window for a git repository to test things with the command
进入 bash 窗口。我为 git 存储库启动了一个新的 bash 窗口,以使用命令进行测试
git rebase -i HEAD~10
and the file opened in Notepad++ as hoped.
并按希望在 Notepad ++ 中打开文件。