How do I use Notepad++ (or other) with msysgit?
GitConfigurationText EditorNotepad++MsysgitGit Problem Overview
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 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
Git Solutions
Solution 1 - Git
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++:
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:
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
Solution 2 - Git
Update 2010-2011:
zumalifeguard's solution (upvoted) is simpler than the original one, as it no longer needs 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:\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 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 a cygwin
path and npp
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 must Settings>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"'
Solution 3 - Git
This works for me
git config --global core.editor C:/Progra~1/Notepad++/notepad++.exe
Solution 4 - Git
git config core.editor "\"C:\Program Files (x86)\Notepad++\notepad++.exe\""
Solution 5 - Git
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
.
During the installation you'll see the following screen:
Solution 6 - Git
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:
git config --global core.editor notepad++
Also, you may add some additional parameters for Notepad++:
git config --global core.editor "notepad++.exe -multiInst"
(as I detailed in "Git core.editor
for Windows")
And here you can find some options you may use when stating Notepad++ Command Line Options.
Solution 7 - Git
UPDATE 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
git config --global core.editor c:/utils/npp/npp.exe
No wrapper scripts or other trickery. No need to have Notepad++ in PATH.
Solution 8 - Git
I am using Windows 10 and notepad++, and I was getting this error message:
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
Solution 9 - Git
Here is a solution with Cygwin:
#!/bin/dash -e
if [ "$1" ]
then k=$(cygpath -w "$1")
elif [ "$#" != 0 ]
then k=
fi
Notepad2 ${k+"$k"}
-
If no path, pass no path
-
If path is empty, pass empty path
-
If path is not empty, convert to Windows format.
Then I set these variables:
export EDITOR=notepad2.sh
export GIT_EDITOR='dash /usr/local/bin/notepad2.sh'
-
EDITOR allows script to work with Git
-
GIT_EDITOR allows script to work with Hub commands
Solution 10 - Git
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 gitpad on your system. Note the last I checked the download link was broken, so download it from here as explained.
Then while committing you should see your favorite text editor popping up.
Solution 11 - Git
I used starikovs' solution. I started with a bash window and gave the commands
cd ~
touch .bashrc
Then I found the .bashrc file in windows explorer, opened it with notepad++ and added
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
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
git rebase -i HEAD~10
and the file opened in Notepad++ as hoped.