如何全局配置git在提交信息时使用特定的编辑器(例如vim
)?
如何全局配置git在提交信息时使用特定的编辑器(例如vim
)?
选择一个方法:
在Git配置中设置core.editor
:
git config --global core.editor "vim"
设置环境变量GIT_EDITOR
:
export GIT_EDITOR=vim
设置标准化的VISUAL
和EDITOR
环境变量*:
export VISUAL=vim
export EDITOR="$VISUAL"
注意:设置两个变量并不一定是必需的,但是有些程序可能不使用更正确的VISUAL
。参见VISUAL
与EDITOR
之间的区别。
有些编辑器需要一个--wait
标志,否则它们将打开一个空白页面。例如:
Sublime Text(如果正确设置;或者在subl
的位置使用可执行文件的完整路径):
export VISUAL="subl --wait"
VS Code(在添加了shell command之后):
export VISUAL="code --wait"
git config --global
会写入你个人的(每个用户的)Git配置文件。在Unix上,该文件路径为 ~/.gitconfig
。因此,这将为你所有的代码仓库进行配置。 - Jakub Narębskigit commit --amend
。 - Marco M.-w
参数不是必需的;而 -w {scriptout}
参数会保存您在编辑过程中键入的所有字符,以便以后重放。也许您将其与 -f
混淆了,当调用 Vim 的 GUI 版本时需要使用 -f
参数。也就是说,如果您使用 mvim
,则应该指定编辑器为 mvim -f
而不是 mvim
。 - Rory O'Kane运行:
git config --global core.editor "vim"
从 man git-commit
:
环境变量和配置变量
用于编辑提交日志消息的编辑器将从
GIT_EDITOR
环境变量、core.editor
配置变量、VISUAL
环境变量或EDITOR
环境变量(按此顺序)中选择。
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:
alternatives
系统是管理支持的程序类型默认设置的更简单的方法。 参考链接:https://www.debian-administration.org/article/91/Using_the_Debian_alternatives_system - underscore_dupdate-alternatives
命令会显示已安装的任何编辑器。Koen 只是没有安装 Emacs。 - Majorvim-gtk3
时,默认设置会自动切换到vim
,之前默认为nano
。因此,我认为这可能是为什么有些人从未需要运行此命令并且它按预期工作的原因。 - Alexis Wilke由于提交消息为空而中止提交。
Sublime无法保持焦点。
为了解决这个问题,我打开了c:/users/username/文件夹中的.gitconfig文件,并在单引号外添加了以下带有--wait选项的行。
[core]
editor = 'F:/Program Files/Sublime Text 2/sublime_text.exe' --wait
git config --global core.editor "'C:/Program Files/Sublime Text 3/subl.exe' --wait"
- KayakinKoderC:\ Users \ YOUR_USERNAME \ .gitconfig
[core]
editor = 'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar
使用32位Notepad++:
[core]
editor = 'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar
git commit
并按Enter
。它会弹出Notepad++。-multiInst
作为参数添加到Notepad++中,并可能需要添加-notabbar
。这样做即可。请注意,不要改变原意。 - ErikE>git config --global core.editor '"C:/Program Files (x86)/Notepad++/notepad++.exe"'
。 - Josef-multiInst
和-notabbar
都是必需的。这个问题困扰了我几个小时。 - Technexteditor = 'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar
- 也就是说,在单引号之外加入参数。 - cropredy要将Visual Studio Code (vscode
) 设为默认的git编辑器:
git config --global core.editor "code --wait"
如果你和使用命令行的设计师一起工作,那么Pico是一个不错的选择,而且不需要掌握快捷键 ;)
git config --global core.editor "pico"
或者
export VISUAL=pico
export EDITOR=pico
git config --global core.editor "atom --wait"
为使上述操作生效,需要对Atom进行命令行配置:
OS X:从Atom菜单栏中安装shell命令:Atom > Install Shell Commands
Windows:无需操作-默认情况下atom已配置为可从命令行运行
git config --global core.editor "code --wait"
- Bar Horing运行以下命令:
$ git config --global core.editor "/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl"
或者只需:
$ git config --global core.editor "subl -w"
-w
参数。例如:$ git config --global core.editor "code -w"
。很棒的东西。 - Automaticosudo update-alternatives --config editor
git config --global core.editor vim