我在使用
nvim
作为我的 git 编辑器时遇到问题。我已将 nvim
指定为全局 core.editor
,但每次需要提交时都需要运行 git commit
两次。我应该如何正确指定 nvim
作为默认提交消息编辑器?
基本上,我目前的工作流程是运行
$ git commit # the first one fails.
$ git commit # this one works.
我遇到的错误:
hint: Waiting for your editor to close the file... error: There was a problem with the editor '/usr/bin/nvim'.
Please supply the message using either -m or -F option.
我用
:wq
编写并关闭提交消息,如果这有什么用的话。
nvim
版本:
$ nvim --version
NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1702233742
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/usr/share/nvim"
Run :checkhealth for more info
git
版本:
$ git --version
git version 2.44.0
终端:
rxvt-unicode (urxvt) v9.31 - released: 2023-01-02
任何帮助表示赞赏!
由于 Neovim 与终端交互的方式,有时可能会出现此问题。
一种解决方法是将 Neovim 配置为以在编辑完成时向 Git 发出信号的方式运行。您可以通过在 core.editor 配置中设置等待标志来完成此操作。具体方法如下:
git config --global core.editor "nvim -f"
-f 标志告诉 Neovim 在“前台”模式下运行,这使得它等到文件关闭后再将控制权返回到终端。这应该允许 Git 检测提交消息编辑何时完成。