Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I would prefer to write my commit messages in Vim, but git 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.

like image 656
brasskazoo Avatar asked Apr 08 '10 00:04

brasskazoo


People also ask

How do I change the default git editor?

The command to do this is git config --global core. editor "nano" . You can change the highlighted section with your editor of choice!

How do I use git config editor?

How to do a git config global edit? The global git config is simply a text file, so it can be edited with whatever text editor you choose. Open, edit global git config, save and close, and the changes will take effect the next time you issue a git command. It's that easy.


1 Answers

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"

OR

  • 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" 

NOTE: 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"

like image 148
digitaldreamer Avatar answered Sep 29 '22 00:09

digitaldreamer