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


git config --global core.editor "vim"

From man git-commit:


The editor used to edit the commit log message will be chosen from the GIT_EDITOR environment variable, the core.editor configuration variable, the VISUAL environment variable, or the EDITOR environment variable (in that order).

Setting the default editor for Git

Pick one:

  • Set core.editor in your Git config:

    git config --global core.editor "vim"
  • Set the GIT_EDITOR environment variable:

    export GIT_EDITOR=vim

Setting the default editor for all programs

Set the standardized VISUAL and EDITOR environment variables*:

export VISUAL=vim

NOTE: Setting both is not necessarily needed, but some programs may not use the more-correct VISUAL. See VISUAL vs. EDITOR.

Fixing compatibility issues

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"

On Ubuntu and also Debian (thanks @MichielB) changing the default editor is also possible by running:

sudo update-alternatives --config editor

Which will prompt the following:

There are 4 choices for the alternative editor (providing /usr/bin/editor).

  Selection    Path                Priority   Status
  0            /bin/nano            40        auto mode
  1            /bin/ed             -100       manual mode
  2            /bin/nano            40        manual mode
* 3            /usr/bin/vim.basic   30        manual mode
  4            /usr/bin/vim.tiny    10        manual mode

Press enter to keep the current choice[*], or type selection number: