git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
Git may be a versioning tool, but it does require a text editor for things like commit messages. If you have used Git on Windows from the command line, you may be familiar with this screen:
# Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master # Changes to be commited: # (use "git reset HEAD <file>..." to unstage) # # modified: foo.c # # Changes not staged for commit: # (use "git add/rm <file>..." to update what will be commited) # (use "git checkout -- <file>..." to discard changes in working directory) # # new file: bar.h # # Untracked files: # (use "git add <file>..." to include in what will be commited) ~ ~ ~
This is Vim, a popular text editor on Linux. It comes with Git for Windows, which defaults to Vim for any text editing.
If you’re stuck there, like so many others, rest assured: It’s not your fault. Exiting Vim is so counter-intuitive that it’s one of the most popular StackOverflow questions of all time!
Surely there must be a better way for us Windows users.
Git is very flexible, and it permits to use other text editors besides Vim – the latter just being provided as a default.
The magic is in the git config core.editor command.
First of all: Install Notepad++. Duh!
Remember Notepad++’s location. If you haven’t changed the defaults, it should be C:/Program Files/Notepad++/notepad++.exe. Use it in a command prompt like so:
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
--global applies this setting across all Git repositories on your computer. If you want to use Notepad++ just with one specific repo, check out the other possible values.
The quoting on this command line took me a few attempts to get right. You see that the path must be quoted, and then the whole command line must be quoted again.
-multiInst opens a new Notepad++ instance especially for Git. This is useful if you have Notepad++ open all day (like me) and don’t want to close your main instance for every commit!
-notabbar gets us back a little screen estate: Git will always ever open a single document in Notepad++, so we don’t need the multi-document tabs.
-nosession: Do not restore any previously opened documents when opening Notepad++.
-noPlugin was recommended to me by StackOverflow. It speeds up loading of Notepad++ if you have many plugins installed. I don’t need it, but I included it here for the sake of completenes.
After successfully running this command, Git should spawn Notepad++ whenever it asks you for a commit message:
Edit and save the file normally. Git resumes once you close Notepad++.