Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does `:Wq` in VIM cause my commit to fail later?

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>?

like image 493
JKillian Avatar asked Dec 24 '15 15:12

JKillian


1 Answers

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.

like image 55
Jonathan.Brink Avatar answered Sep 19 '22 18:09

Jonathan.Brink