Make Notepad++ Git's default editor

Git's command-line tools are relatively easy to learn, but one thing regularly surprises Windows developers: run git commit without the -m option and Git may suddenly drop you into an unfamiliar text editor.

Depending on how Git is installed and configured, that editor may be Vim. Vim is extremely powerful, but if you normally work in Windows applications, figuring out how to enter a commit message, save the file and exit Vim can be an unnecessary distraction.

If Notepad++ is your preferred text editor, simply configure Git to use it instead.

Changing away from Vim as the default Git text editor

Notepad++ can replace Vim as Git's default editor on Windows.

Set Notepad++ as the Git editor

Git stores the editor it should launch in the core.editor configuration property.

If Notepad++ is installed in its standard 64-bit Windows location, run the following command from Git Bash:

git config --global core.editor \
  "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession"

The --global option applies this setting to repositories used by your Windows account. You only need to configure it once.

If your installation of Notepad++ is somewhere else, simply change the path to notepad++.exe.

Verify Git's configured editor

You do not need to open the .gitconfig file manually to check the setting. Ask Git directly:

git config --global --get core.editor

You should see output similar to this:

'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession

You can also inspect where Git obtained the setting:

git config --show-origin --get core.editor

This is particularly useful if you have repository-specific, global and system-level Git configuration settings and want to know which configuration file is actually being used.

What changes in .gitconfig?

Because the command uses --global, Git normally stores the setting in the .gitconfig file in your home directory.

The configuration will look similar to this:

[core]
    editor = 'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession
Making Notepad++ the default Git text editor

The core.editor setting tells Git to launch Notepad++ when an interactive text editor is required.

Why use the Notepad++ command-line options?

The arguments after notepad++.exe belong to Notepad++, not Git.

  • -multiInst tells Notepad++ to start another instance.
  • -notabbar hides the tab bar for the temporary editing window.
  • -nosession prevents Notepad++ from restoring files from an earlier session.

The important option for Git integration is -multiInst. Git launches an editor and waits for that editor process to finish. A separate Notepad++ process makes that behavior straightforward: enter the message, save the file and close the Notepad++ window.

Test Notepad++ with a Git commit

Once the editor is configured, make a change to a repository, stage it and run git commit without the -m option:

git add .
git commit

Git should launch Notepad++ and display the temporary commit-message file.

Enter your commit message at the top of the file:

Fix the application's login validation

Save the file and close the Notepad++ window. Git reads the saved message and completes the commit.

Lines beginning with # are informational comments supplied by Git and are not normally included in the final commit message.

Test Git's editor without creating a commit

If you only want to verify that Git can launch the configured editor, modern Git provides a convenient command:

git var GIT_EDITOR

This displays the editor Git has resolved from its configuration and environment.

You can also test the editor during an actual operation such as git commit, which verifies that Git can both launch the editor and wait for it to close.

Set Notepad++ for only one repository

You may not want Notepad++ to become the editor for every Git repository on your machine.

To configure it only for the current repository, omit --global:

git config core.editor \
  "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession"

Git stores that value in the current repository's .git/config file, and it takes precedence over the global setting while you work in that repository.

Change Git back to Vim

If you later decide that Vim really is your preferred editor, change the setting again:

git config --global core.editor "vim"

Or remove your explicit global editor configuration entirely:

git config --global --unset core.editor

Git will then resolve its editor from the remaining Git configuration, environment variables and platform defaults.

Notepad++ is used for more than commits

The core.editor setting is not limited to commit messages. Git invokes its editor whenever an operation requires you to interactively edit text.

That can include:

  • Git commit messages;
  • merge commit messages;
  • tag messages;
  • some rebase operations; and
  • other Git commands that require an editor.

So if Vim is the only thing keeping you from feeling comfortable at the Git command line on Windows, there is no requirement to use it. Configure core.editor once, point it at Notepad++, and Git will use the editor you already know.