如何全局配置git以使用特定的编辑器(例如vim)提交消息?


当前回答

只需尝试EDITOR=vim-gitcommit。

或者可以通过在bashrc中导出EDITOR=vim将EDITOR设置为vim。

其他回答

在Ubuntu和Debian(谢谢@MichielB)上,也可以通过运行以下命令来更改默认编辑器:

sudo update-alternatives --config editor

这将提示以下内容:

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: 

使用git review时,我必须修改sequence.editor值,以便能够进行交互式rebase(gitrebase-I-p):

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

gvim要求:apt-installvim-gtk

工具书类

#2944 Interactive Rebase失败,出现警告:“Vim:警告:输出不到终端”安装sjubar/rebase编辑器的部分

对于Mac OS X,使用TextEdit或自然环境编辑器编辑文本:

git config --global core.editor "open -W -n"

在Git配置中设置core.editor:

git config --global core.editor "nano"

设置GIT_EDITOR环境变量:

export GIT_EDITOR=nano

对于Textmate用户

这将在您想要编辑提交时打开Textmate编辑器。需要安装textmate命令行工具。

git-config--全局core.editor“mate-w”