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


当前回答

对于希望将neovim与Windows Subsystem For Linux一起使用的Windows用户:

git-config-core.editor“C:\Windows/system32/bash.exe--login-C'nvim.git/COMMIT_EDITMSG'”

这不是一个傻瓜式的解决方案,因为它不处理交互式的重新基础(例如)。非常欢迎改进!

其他回答

设置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”

如果你正在使用命令行与设计师合作,那么Pico,而且不知道捷径;)

git config --global core.editor "pico"

Or

export VISUAL=pico
export EDITOR=pico

对于Textmate用户

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

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

对于emacs用户

.emacs:

(server-start)

外壳:

export EDITOR=emacsclient

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