I would prefer to write my commit messages in Vim, but it is opening them in Emacs.
How do I configure Git to always use Vim? Note that I want to do this globally,
git config --global core.editor notepad.exe
Hit Ctrl+S to save your commit message. To discard, just close the notepad window without saving.
In case you hit the shortcut for save, then decide to abort, go to File->Save as, and in the dialog that opens, change "Save as type" to "All files (*.*)". You will see a file named "COMMIT_EDITMSG". Delete it, and close notepad window.
Edit: Alternatively, and more easily, delete all the contents from the open notepad window and hit save. (thanks mwfearnley for the comment!)
I think for small write-ups such as commit messages notepad serves best, because it is simple, is there with windows, opens up in no time. Even your sublime may take a second or two to get fired up when you have a load of plugins and stuff.
Copy paste this:
git config --global core.editor "vim"
In case you'd like to know what you're doing. From man git-commit
:
ENVIRONMENT AND CONFIGURATION VARIABLES
The editor used to edit the commit log message will be chosen from the
GIT_EDITOR
environment variable, thecore.editor
configuration variable, theVISUAL
environment variable, or theEDITOR
environment variable (in that order).
This provides an answer for people who arrive at this Question that may want to link an editor other than vim.
The linked resource, by Github,is likely to be kept up to date, when editors are updated, even if answers on SO (including this one) are not.
Associating Text Editors with git
Github's post shows exactly what to type in to your command line for various editors, including the options/flags specific to each editor for it to work best with git.
Notepad++:
git config --global core.editor "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
Sublime Text:
git config --global core.editor "'c:/Program Files/sublime text 3/subl.exe' -w"
Atom:
git config --global core.editor "atom --wait"
The commands above assume your editor has been installed in the default directory for a windows machine.
The commands basically add the text between double-quotes to .gitconfig
in your home directory.
On a windows machine home is likely to be C:\Users\your-user-name
, where your-user-name is your login name.
From the command line, you can reach this directory by typing in cd ~
.
for example, a command above would be add the following line under the [core]
section like so:
[core]
editor = 'C:/Program Files/sublime text 3/subl.exe' -w
If you have a different editor, just replace with the path to your editor, using either method above. (and hope no flags are needed for optimal usage.)
Like all the other GUI applications, you have to launch mvim with the wait flag.
git config --global core.editor "mvim --remote-wait"
For Windows, Neovim:
# .gitconfig
[core]
editor='C:/tools/neovim/Neovim/bin/nvim-qt.exe'
And if you are working with designers using the command line then Pico, and dont know short cuts ;)
git config --global core.editor "pico"
Or
export VISUAL=pico
export EDITOR=pico