我如何让Git使用我选择的编辑器进行提交?

我宁愿在Vim中编写我的提交消息,但它在Emacs中打开它们。

我如何配置Git来始终使用Vim? 请注意,我想在全球范围内执行此操作,而不仅仅针对单个项目。


如果您只想为Git设置编辑器,请执行以下任一操作(您不需要两者):

  • 在你的Git配置中设置core.editorgit config --global core.editor "vim"
  • 设置GIT_EDITOR环境变量: export GIT_EDITOR=vim

  • 如果您想为Git和其他程序设置编辑器,请设置标准化的VISUALEDITOR环境变量*:

    export VISUAL=vim
    export EDITOR="$VISUAL"
    

    *设置两者并不一定需要,但有些程序可能不会使用更正确的VISUAL 。 参见VISUALEDITOR


    对于Sublime Text :将其添加到.gitconfig 。 - --wait很重要。 (它允许在崇高中输入文本并等待保存/关闭事件。

    [core]
        editor = 'subl' --wait
    

    'subl'可以替换为可执行文件的完整路径,但通常在正确安装时可用。


    复制粘贴:

    git config --global core.editor "vim"
    

    如果你想知道你在做什么。 从man git-commit

    环境和配置变量

    用于编辑提交日志消息的编辑器将从GIT_EDITOR环境变量, core.editor配置变量, VISUAL环境变量或EDITOR环境变量( core.editor顺序)中进行选择。


    在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: 
    
    链接地址: http://www.djcxy.com/p/3865.html

    上一篇: How do I make Git use the editor of my choice for commits?

    下一篇: What's a quick way to comment/uncomment lines in Vim?