Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I have this strange problem with using vi as the editor for git commit -a.

Normal flow is: I type git commit -a, vi appears, I enter my commit message, and then :wq to save & exit from vi.

This works fine. However, sometimes I make a typo and instead of :wq I type :Wq (because I use the shift for :). Then, when I correct myself and type :wq again, git gives the following error:

error: There was a problem with the editor 'vi'.
Please supply the message using either -m or -F option.

How can I fix this?

share|improve this question
    
What version of git and vi? I can't repro this with vim 7.3, git version 1.7.11.1. –  Christopher Jul 26 '12 at 22:00
    
@Christopher : vi 7.3 and git 1.7.9.6 (Apple Git-31.1), the default ones on Mountain Lion afaik –  houbysoft Jul 26 '12 at 23:07

3 Answers 3

up vote 13 down vote accepted

vi is existing with a non-zero status, although without additional details about your setup, it's difficult to tell why. If you're using a lot of plugins to vim, you might try moving your .vimrc file to .vimrc.back and seeing if you can replicate. There are a few sources that discuss this problem, including at least one with a potential solution:

git config --global core.editor /usr/bin/vim

I would try removing your .vimrc first, however. It seems to cause more consternation.

share|improve this answer
5  
Thanks, git config --global core.editor /usr/bin/vim fixed it. –  houbysoft Jul 27 '12 at 13:04

Do you use the golang vim plugins? This line is causing the vi exit value problem for me: filetype plugin indent off

Removing the whole golang plugin block in .vimrc fixed the problem. Installing the golang plugin using fugitive can be as easy as: ln -s $GOROOT/misc/vim ~/.vim/bundle/vim-golang

(I just documented the problem in this issue on the vim-golang github)

share|improve this answer

As answered here: http://stackoverflow.com/questions/22699614/git-commit-messages-lost-by-vi

The real solution is to

git config --global core.editor vim -f

According to vim documentation - -f option should be used when Vim is executed by a program that will wait for the edit session to finish

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.