213

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
PHLAK
  • 22,023
  • 18
  • 49
  • 52
  • 1
    Any error messages? Have you tried setting the EDITOR environment variable? – csl Oct 27 '09 at 23:05
  • 4
    Try looking here: http://stackoverflow.com/questions/10564/how-can-i-set-up-an-editor-to-work-with-git-on-windows – JasonTrue Oct 27 '09 at 23:50
  • Possible duplicate of [How can I set up an editor to work with Git on Windows?](http://stackoverflow.com/questions/10564/how-can-i-set-up-an-editor-to-work-with-git-on-windows) – Jim Fell Mar 14 '17 at 12:30

11 Answers11

436
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

zumalifeguard
  • 8,648
  • 5
  • 43
  • 56
  • 9
    works in git extensions too. note that for 64bit windows the entry is `"C:/Program Files (x86)/Notepad++/notepad++.exe" -multiInst -notabbar -nosession -noPlugin` – Tim Abell Jun 13 '12 at 12:01
  • 15
    The silly thing is that -notabbar will disable the tab bar permanently, not just for that session. When launchin notepad++ normally, you have to go into the settings dialog an enable the tab bar again. – Oskar Berggren Jan 10 '13 at 10:01
  • 4
    I had to use: `git config --global core.editor "c\:/Program\ Files\ \(x86\)/Notepad++/notepad++.exe -multiInst -nosession -noPlugin"` ...not sure why. – David Faivre Feb 12 '13 at 19:34
  • git rebase was not rebasing my commits. I was amending them using notepad++.exe. I changed the editor settings of git config as mentioned in this answer and magically git rebase started rebasing. I suspect it is to do with the parameters being passed in to notepad++.exe. – Chirayu Shishodiya Oct 31 '14 at 18:07
  • 1
    I have Windows 7 64-bit, msysgit v1.9.2 and Notepad++ v6.6.9 and this worked **PERFECTLY**. Thanks. – Radu Murzea Jan 21 '15 at 15:13
  • You can use backslashes if you escape them, i.e. `"C:\\Program..."` – Mark Ingram Aug 26 '15 at 15:11
  • 1
    Any reason why it shall launch a new Notepad++ process, without session, plugins and tab bar? Doesn't it work if it's already running? – CodeManX Sep 09 '15 at 02:13
  • 2
    @CoDEmanX Without `-multiInst` it will likely just signal the already running Notepad++ to open the file and then exit immediately. This can be a big problem if whatever calls the editor expects it to return only when done editing (i. e. a synchronous operation, as is the case when calling vi). Try an interactive rebase (`git rebase -i`), for instance. If this still works as expected, then you're fine. – blubberdiblub Jan 09 '16 at 05:20
  • but how to launch notepad++ within git repo? – Bhushan Gadekar Apr 21 '16 at 08:55
  • Thanks! Worked for me, but with a slight edit: git config --global core.editor "'C:\Program Files (x86)\Notepad++\notepad++.exe' -multiInst -notabbar -nosession -noPlugin". – Ofer Dec 01 '16 at 12:17
  • Ofer, I see that the only change you made is changing the forward slashes to backslashes. Did you do it because the forward slashes didn't work? – zumalifeguard Dec 10 '16 at 01:35
  • 1
    For even cooler integration, add "-ldiff". this will add syntax highlighting – Hilikus May 16 '17 at 17:12
78

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"'
    
TylerH
  • 20,799
  • 66
  • 75
  • 101
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I got this to work by placing npp.sh in the root of my drive (ie - C:/npp.sh). Any time I try to target a folder with spaces (ie - D:/Program Files (x86)/Git/npp.sh) in it it fails, what's the proper way to escape spaces and/or get this to work? – PHLAK Nov 01 '09 at 02:16
  • put quotes around it. See how he has quotes around the entire thing in his example? – Fred Nov 18 '09 at 22:42
  • 1
    I have tried multiple combinations of the above and none work with git. i have my npp script in my path and if from my cygwin console i type, "npp {file}" npp opens the file just fine, but when i do a "git rebase -i" npp opens with a blank file instead of the merge file. any ideas why this would happen? – scphantm Apr 18 '12 at 12:28
  • @scphantm strange. I would advise for posting a new question, with a link to this answer, and many more details (Git version, OS version, npp version, content of the script, ...) – VonC Apr 18 '12 at 12:31
7

This works for me

git config --global core.editor C:/Progra~1/Notepad++/notepad++.exe
Zombo
  • 1
  • 62
  • 391
  • 407
Tim Scott
  • 15,106
  • 9
  • 65
  • 79
  • i did the same.. now how to open notepad++ to commit with message?? what is the commad?? please can you give an example – Shridutt Kothari Jul 10 '15 at 06:33
  • 4
    Adding the `-multiInst` option is crucial here, like in the other answers. – blubberdiblub Jan 09 '16 at 05:24
  • 1
    This is not good for two reasons. First, if the C: volume is NTFS with the 8.3 filename option turned off, there is no `C:\Progra~1` at all. Second, there may be multiple `C:\Progra*` directories, so the `~1` suffix is not necessarily the valid one. – kkm inactive - support strike Oct 24 '16 at 07:23
6
git config core.editor "\"C:\Program Files (x86)\Notepad++\notepad++.exe\""
Roman Marusyk
  • 23,328
  • 24
  • 73
  • 116
Jus
  • 174
  • 1
  • 2
  • That did the trick for me! Afterwards the .gitconfig looks like: [core] editor = \"c:\\Program Files (x86)\\Notepad++\\notepad++.exe\" -multiInst -nosession -noPlugin – AtliB May 29 '17 at 12:05
  • See highest voted answer, which includes this (I didn't read far enough) – AtliB May 29 '17 at 12:21
5

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:

enter image description here

AXO
  • 8,198
  • 6
  • 62
  • 63
4

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
starikovs
  • 3,240
  • 4
  • 28
  • 33
1

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.

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
  • Update 2020: seems that you've missed the options to open new notepad instance. I've used from cmd.exe `git config --global core.editor "c:\\soft\\notepad++\\notepad++.exe -multiInst -notabbar -nosession -noPlugin"` and it is working from both `cmd terminal` and `git bash` – oleksa Feb 07 '20 at 12:50
1

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

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

Here is a solution with Cygwin:

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

  2. If path is empty, pass empty path

  3. 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'
  1. EDITOR allows script to work with Git

  2. GIT_EDITOR allows script to work with Hub commands

Source

Zombo
  • 1
  • 62
  • 391
  • 407
0

Follow these instructions,

  1. First make sure you have notepad++ installed on your system and that it is the default programme to open .txt files.

  2. 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.

Aditya P
  • 1,024
  • 11
  • 10
0

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.

Ivan
  • 4,383
  • 36
  • 27