Reputation: 5568
I'm a clumsy typist, and I don't use vi/vim very often, but I do use it for commit messages. However, if you type a wrong command while editing a commit message (:Wq
, say, instead of :wq
), when you correctly close out the commit message in vim with :wq
or :x
, you get this:
error: There was a problem with the editor 'vi'.
Please supply the message using either -m or -F option.
Normally, a wrong command like :W
is no problem—vim just ignores it and you can keep on working with the file and save it, but in git commit messages as soon as I mistype, I have irrevocably lost the commit message.
What's going on here, and how do I fix it? (Using git 1.9.1 via homebrew, vim 7.3 as packaged with OS X 10.9)
Upvotes: 32
Views: 3800
Reputation: 9938
My solution:
git config --global core.editor vim
I think this is the difference between Vim and Vi (although vi
on most platform is actually Vim running in compatibility mode). Note that Git uses vi
by default, which you can tell from the documentation:
The order of preference is the
$GIT_EDITOR
environment variable, thencore.editor
configuration, then$VISUAL
, then$EDITOR
, and then the default chosen at compile time, which is usuallyvi
.
On my machine (macOS) the full path doesn’t make any difference (which is expected); vim
is the same as /usr/bin/vim
, and vi
is the same as /usr/bin/vi
.
Note: you can also tell the program from the error message:
error: There was a problem with the editor 'vi'.
The quoted vi
is exactly the command for your editor. You can verify that with
GIT_EDITOR='false -a -b' git commit
Upvotes: 1
Reputation: 1095
You should set vim to not detach from the shell and be in the foreground. You can do this with the following command:
git config --global core.editor vim -f
From the man:
-f Foreground. For the GUI version, Vim will not fork and detach from the shell it
was started in. On the Amiga, Vim is not restarted to open a new window. This
option should be used when Vim is executed by a program that will wait for the
edit session to finish (e.g. mail). On the Amiga the ":sh" and ":!" commands
will not work.
Upvotes: 42
Reputation: 16012
As mentioned in several posts vim is exiting with a exit code other than zero. You can fix it by explicitely setting the git editor to the full vim path:
git config --global core.editor /usr/bin/vim
If I remember correctly I fixed the issue by installing a homebrewed vim. Make sure your path is set correctly then.
Upvotes: -1