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

后端 未结 27 2127
庸人自扰
庸人自扰 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 02:03

    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: 
    
    0 讨论(0)
  • 2020-11-22 02:05

    On macOS Big Sur (11.0) beta for TextMate: none of the environment variable options worked. (Set all three: GIT_EDITOR, VISUAL, and EDITOR.)

    Finally set the global core.editor in git, and that worked:
    git config --global core.editor "~/bin/mate -w"

    0 讨论(0)
  • 2020-11-22 02:06

    When using git-review I had to modify sequence.editor value to be able to do interactive rebase (git rebase -i -p):

    git config --global sequence.editor "gvim"  # or whatever your prefer
    

    gvim require: apt install vim-gtk

    References

    • #2944 Interactive Rebase failed with warning: "Vim: Warning: Output is not to a terminal"
    • Install section of sjurba/rebase-editor
    0 讨论(0)
  • 2020-11-22 02:06

    For Textmate Users

    This opens Textmate editor in when you want to edit your commits. Requires textmate command line tools to be installed.

    git config --global core.editor "mate -w"

    0 讨论(0)
  • 2020-11-22 02:08

    For emacs users

    .emacs:

    (server-start)
    

    shellrc:

    export EDITOR=emacsclient
    
    0 讨论(0)
  • 2020-11-22 02:09

    Just try EDITOR=vim git commit.

    Or you can set your EDITOR to vim by export EDITOR=vim in your bashrc.

    0 讨论(0)
提交回复
热议问题