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


当前回答

Windows:将记事本设置为默认的提交消息编辑器

git config --global core.editor notepad.exe

按Ctrl+S保存提交消息。要放弃,只需关闭记事本窗口而不保存。

如果您点击保存快捷方式,然后决定中止,请转到文件->另存为,在打开的对话框中,将“另存为类型”更改为“所有文件(*.*)”。您将看到一个名为“COMMIT_EDITMSG”的文件。删除它,然后关闭记事本窗口。

编辑:或者,更容易地从打开的记事本窗口中删除所有内容,然后单击保存。(感谢姆沃恩利的评论!)

我认为对于诸如提交消息之类的小记录,记事本是最好的,因为它很简单,有窗口,很快就能打开。当你有一大堆插件和东西时,甚至你的崇高也可能需要一两秒钟才能被激发起来。

其他回答

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

对于MAC,BBEdit:

首先,打开BBEdit,单击BBEdit徽标,然后选择Install Command Line Tools。

然后从命令行,

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

对于EmEditor用户

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

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

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

对于Windows,Neovim:

# .gitconfig

[core]
    editor='C:/tools/neovim/Neovim/bin/nvim-qt.exe'

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

git config --global core.editor "pico"

Or

export VISUAL=pico
export EDITOR=pico