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


当前回答

对于Textmate用户

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

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

其他回答

Run:

git config --global core.editor "vim"

来自man git commit:

环境和配置变量用于编辑提交日志消息的编辑器将从GIT_editor环境变量、core.editor配置变量、VISUAL环境变量或editor环境变数中选择(按顺序)。

Mvim作为您的git编辑器

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

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

对于Mac应用商店中TextWrangler的用户:

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

此外,确保“TextWrangler>首选项>应用程序>当TextWranger变为活动时:”设置设置为“不执行任何操作”

这适用于Mac应用商店中使用TextWrangler 5.0.2的OS X 10.11.4。

说明:

-n表示在新实例中打开。

-W表示在使用编辑文件的内容作为提交消息之前,等待应用程序退出。

-a TextWrangler表示使用TextWrangle应用程序打开文件。

有关详细信息,请在Mac终端应用程序中查看man open。

对于EmEditor用户

要将EmEditor设置为Git的默认文本编辑器,请打开Git Bash,然后键入:

git config--全局core.editor“emeditor.exe-sp”

需要EmEditor v19.9.2或更高版本。

在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: