如何全局配置git以使用特定的编辑器(例如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: 

其他回答

对于emacs用户

.emacs:

(server-start)

外壳:

export EDITOR=emacsclient

对于Textmate用户

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

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

Mvim作为您的git编辑器

与所有其他GUI应用程序一样,您必须使用wait标志启动mvim。

git config --global core.editor "mvim --remote-wait"

Atom作为您的git编辑器

git config --global core.editor "atom --wait"

需要将Atom配置为从命令行运行,以使上述功能正常工作:OS X:从Atom安装shell命令:菜单栏>Atom>安装Shell命令Windows:不需要任何操作-默认情况下,atom配置为从命令行运行

设置Git的默认编辑器

选择一个:

在Git配置中设置core.editor:git-config—全局core.editor“vim”设置GIT_EDITOR环境变量:导出GIT_EDITOR=vim


设置所有程序的默认编辑器

设置标准化的VISUAL和EDITOR环境变量*:

export VISUAL=vim
export EDITOR="$VISUAL"

注意:不一定需要同时设置这两个,但某些程序可能不会使用更正确的VISUAL。参见视觉与编辑。


修复兼容性问题

有些编辑器需要--wait标志,否则将打开空白页。例如:

Sublime文本(如果设置正确;或使用可执行文件的完整路径代替subl):export VISUAL=“subl--等待”VS代码(添加shell命令后):export VISUAL=“code--wait”