views:

319

answers:

3

For example, I would prefer to write my commit messages in vim, but it is opening emacs.

How do I configure git to always use vim instead? Note that I want to do this globally, not just for a single project.

+9  A: 

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, the core.editor configuration variable, the VISUAL environment variable, or the EDITOR environment variable (in that order).

Mark Rushakoff
Btw, the above is true for CVS and SVN, and I guess other version controls.
armandino
@armandino: Yes, the others might use `VISUAL` or `EDITOR`, but they certainly don't use `GIT_EDITOR` or `core.editor`.
Mark Rushakoff
Thanks for clarifying Mark. I meant the EDITOR variable. I believe the GIT_EDITOR (if defined) simply overrides it.
armandino
Yep - http://svnbook.red-bean.com/en/1.1/ch07.html#svn-ch-7-sect-1.3.2So in theory, if I'm using both svn and git, setting $VISUAL or $EDITOR would be the best solution to cover both by default!
brass-kazoo
+6  A: 

You can either set core.editor in your git config

git config --global core.editor "vim"

or set the VISUAL or EDITOR environment variables.

export VISUAL=vim
export EDITOR=vim
digitaldreamer
The EDITOR environment variable has the advantage that a number of other programs will respect it as well.
Boojum
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.
Jakub Narębski
@Jakub, well obviously it's global
hasen j
A: 

For emacs users

.emacs:

(server-start)

shellrc:

export EDITOR=emacsclient
Bendlas