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, not just for a single project.
If you want to set the editor only for Git, do either (you don’t need both):
core.editor
in your Git config: git config --global core.editor "vim"
GIT_EDITOR
environment variable: export GIT_EDITOR=vim
If you want to set the editor for Git and also other programs, set the standardized VISUAL
and EDITOR
environment variables*:
export VISUAL=vim
export EDITOR="$VISUAL"
* Setting both is not necessarily needed, but some programs may not use the more-correct VISUAL
. See VISUAL
vs. EDITOR
.
Some editors require a --wait
flag, or they will open a blank page. For example:
Sublime Text (if correctly set up; or use the full path to the executable in place of subl
):
export VISUAL="subl --wait"
VS Code (after adding the shell command):
export VISUAL="code --wait"
The EDITOR environment variable has the advantage that a number of other programs will respect it as well.
Note that
git config --global
would write to your personal (per-user) git configuration file. On Unices it is~/.gitconfig
. So this would configure it for all your repositories.you can test you successfully changed it by trying to amend the last commit message.
git commit --amend
If you're doing option #1 in Windows and have spaces in the path to the editor (say, if it's under Program Files) then whack single-quotes inside your double-quotes. e.g. "'C:/Program Files (x86)/Whatever/App.exe'" - obvious to some but it wasn't to me!
@Abramodj
-w
is not necessary;-w {scriptout}
saves all characters you type when editing to replay later. Perhaps you are confusing it with-f
, which is necessary when calling the GUI version of Vim. That is, if you usemvim
, then the editor you specify should bemvim -f
rather thanmvim
.