Reputation: 18351
Often when I'm finished writing a commit message in VIM, I type :Wq<ENTER>
instead of :wq<ENTER>
because I'm holding down the shift key to type the colon. This causes VIM to respond with E492: Not an editor command: Wq
.
This is all fine so far, I just retype :wq<ENTER>
to save the commit message and exit VIM. However, the commit does not work then, and the terminal shows something like this:
$ git commit
$ error: There was a problem with the editor 'vi'.
$ Please supply the message using either -m or -F option.
Why does accidentally entering :Wq<ENTER>
before doing the correct :wq<ENTER>
cause the commit to fail? Is there any way to get the commit to happen after entering :Wq<ENTER>
?
Upvotes: 7
Views: 7031
Reputation: 6491
I couldn't replicate this issue. That is, I was able to get the E492: Not an editor command: Wq
error, but running :wq
afterwards successfully closed vim and saved the commit.
Perhaps you can try something similar to this answer - https://stackoverflow.com/a/117221/864233
:command WQ wq
:command Wq wq
:command W w
:command Q q
Save those four "aliases" to a file in ~/.vimrc
and if you accidentally run :Wq
again, it won't error out on you.
Also, as Jonathan.Brink noted above, make sure you're actually using vim and not vi, as that may be causing some issues as well.
Upvotes: 5
Reputation: 25423
This article seems to describe a similar issue.
Looks like when you use the capital 'W' Vim is exiting with an error code when invoked by Git.
Have you tried:
git config --global core.editor /usr/bin/vim
(or wherever you have vim installed on your system)...which seemed to clear up the issue. Must be related to how how Git invokes Vim.
Also, see this question which indicates that it may have to do with the filetype
setting.
Upvotes: 5