Git for Windows tip: setting an editor

The first time I tried to do git commit on msysgit with no commit message (no –m switch), it opened up Vim so that I could write my commit message. Luckily for me I’d read enough Vim jokes on Twitter to know that :q or :q! would get me out. But there is no way I’d be able to actually write a commit message, save and quit in Vim (that’d probably take about 3 weeks of studying the documentation). Much easier to change the editor for git to Notepad++ or some other more familiar text editor.

The first step is to create a bat file (I called mine npp.bat) with the path to Notepad++ and the appropriate switches:

"C:/Program Files (x86)/Notepad++/notepad++.exe" -multiInst -notabbar -nosession -noPlugin "$*"

This opens a new instance of Notepad++ with no sessions or tabs or plugins which is what I want when writing a commit message. Place the bat file in the git subdirectory of msysgit (c:\msysgit\git on my system) and then set the core.editor variable in git config:

git config --global core.editor c:/msysgit/git/npp.bat

See this answer on Stackoverflow for more variations on this.

The next step is to get Notepad++ to work from the command line. I want to be able to write:

notepad .bashrc

and Notepad++ should open the .bashrc file. This is actually nothing to do with msysgit and involves replacing the default notepad application with Notepad++ in Windows. And the easiest way is to use a program called Notepad Replacer. Install this and voila, it now works. If you ever want to revert to the default notepad then just uninstall Notepad Replacer.

The other option is create a script file just like the npp.bat file but without the switches and name it npp with no extension and place it in the bin folder. Now I can write:

npp .bashrc

and it opens the file in Notepad++. This approach also works for any third party editor such as Word or Excel.

EDIT: An alternative way to achieve the same result is to install Gitpad to change the default editor to Notepad (or the default text editor).

8 thoughts on “Git for Windows tip: setting an editor

    1. Hi Blake, it was a joke – just trying to express the feeling of very unexpectedly being thrown into VI when on Windows (especially in 2011 when I wrote this post). Yes, VI is handy when ssh:ing into servers or quickly changing a config file if you are on Linux but this is a Git for Windows tip and VI is/was totally foreign for most Windows devs (though that might change now that Windows 10 is getting proper Bash). I am mostly developing on Ubuntu these days and there I write my commit messages with VI as it is available on just about every UNIX system.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s