Warm tip: This article is reproduced from serverfault.com, please click

How do I make Git use the editor of my choice for commits?

发布于 2010-04-08 00:28:46

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.

Questioner
brasskazoo
Viewed
0
26.7k 2021-02-03 23:22:54

If you want to set the editor only for Git, do either (you don’t need both):

  • Set core.editor in your Git config: git config --global core.editor "vim"
  • Set the 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"