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

后端 未结 27 2699
庸人自扰
庸人自扰 2020-11-22 01:33

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,

27条回答
  •  忘掉有多难
    2020-11-22 01:52

    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.


    For Sublime Text: Add this to the .gitconfig. The --wait is important (it allows to type text in sublime and will wait for save/close event.)

    [core]
        editor = 'subl' --wait
    

    'subl' can be replaced by the full path of the executable but is usually available when correctly installed.

提交回复
热议问题