Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git Commit Problem: "error: There was a problem with the editor 'vi'" #167

Closed
codyaray opened this issue Apr 22, 2012 · 31 comments

Comments

@codyaray
Copy link

commented Apr 22, 2012

I'm just starting to use Vundle and I'm running into an error when editing a Git message using the .vimrc setup from the README. When I try to save any git message in vim, I get the following error.

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

I've tracked this down to the initial filetype off directive (marked as required in the README). I don't understand why its causing this issue, but after commenting out the line, but this re-enabled Git commit editing in vim.

Can you shed some light on why its "required" to disable filetype detection before using vundler? And then to re-enable it (using filetype plugin indent on) later on?

FWIW, my vim version:

$ vim --version
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Jun 24 2011 20:00:09)
Compiled by root@apple.com
Normal version without GUI.  Features included (+) or not (-):
-arabic +autocmd -balloon_eval -browse +builtin_terms +byte_offset +cindent 
-clientserver -clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments 
-conceal +cryptv +cscope +cursorbind +cursorshape +dialog_con +diff +digraphs 
-dnd -ebcdic -emacs_tags +eval +ex_extra +extra_search -farsi +file_in_path 
+find_in_path +float +folding -footer +fork() -gettext -hangul_input +iconv 
+insert_expand +jumplist -keymap -langmap +libcall +linebreak +lispindent 
+listcmds +localmap -lua +menu +mksession +modify_fname +mouse -mouseshape 
-mouse_dec -mouse_gpm -mouse_jsbterm -mouse_netterm -mouse_sysmouse 
+mouse_xterm +multi_byte +multi_lang -mzscheme +netbeans_intg -osfiletype 
+path_extra -perl +persistent_undo +postscript +printer -profile -python 
-python3 +quickfix +reltime -rightleft -ruby +scrollbind +signs +smartindent 
-sniff +startuptime +statusline -sun_workshop +syntax +tag_binary 
+tag_old_static -tag_any_white -tcl +terminfo +termresponse +textobjects +title
 -toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo 
+vreplace +wildignore +wildmenu +windows +writebackup -X11 -xfontset -xim -xsmp
 -xterm_clipboard -xterm_save 
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -D_FORTIFY_SOURCE=0 -Iproto -DHAVE_CONFIG_H -arch i386 -arch x86_64 -g -Os -pipe
Linking: gcc -arch i386 -arch x86_64 -o vim -lncurses
@phildobbin

This comment has been minimized.

Copy link

commented Apr 22, 2012

I think it's to enable Vundle to bypass $VIMRUNTIME when installing & then you re-set to enable the use of filetypes.

See:

h: filetype

I'm sure our author can elucidate further :-)

@gmarik

This comment has been minimized.

Copy link
Contributor

commented Apr 30, 2012

@codyaray as @phildobbin it's required to set filetype detection properly.

It's usually hard to say what causing issues for you without looking .vimrc.
Also i'd like to know what $EDITOR is set to.

Closing issue, as suspect it's just a configuration issue.
Feel free to comment if you still having issues.

@gmarik gmarik closed this Apr 30, 2012

@sent-hil

This comment has been minimized.

Copy link

commented Dec 30, 2012

git config --global core.editor /usr/bin/vim solved it for me.

@ruebenramirez

This comment has been minimized.

Copy link

commented Dec 12, 2013

git config --global core.editor $(which vim)

@liyicky

This comment has been minimized.

Copy link

commented Feb 3, 2014

git config --global core.editor $(which vim) works. Very strange however because I was always using /usr/bin/vim. Whatever I guess.

@coryfklein

This comment has been minimized.

Copy link

commented Jun 30, 2014

This worked for me too:

git config --global core.editor $(which vim)

@hughgr

This comment has been minimized.

Copy link

commented Jul 4, 2014

git config --global core.editor $(which vim)

that works

@cbeams

This comment has been minimized.

Copy link

commented Jul 16, 2014

I just went through this process as well:

  1. Install Vundle per instructions
  2. Try to commit something as per usual with git commit
  3. Type a commit message using $EDITOR, which is set to vi
  4. Watch commit fail with "error: There was a problem with the editor 'vi'."
  5. Search for a solution, find this blog post
  6. Try the workaround it suggests (git config --global core.editor $(which vim)), notice that it works
  7. Notice that it also works to reset $EDITOR from vi to /usr/bin/vim
  8. Feel frustrated, because no one seems to understand why this is happening
  9. Search for related issues in the Vundle GitHub repo, find this issue
  10. Remain frustrated because while everyone agrees on the workaround, there is still no actual explanation or solution
  11. Realize that this is a cycle that many more users will struggle through unless a proper fix shows up
  12. Write this comment in hopes the issue might be reopened

I'm using Vim 7.3. Thanks for Vundle. Looking forward to using it.

cbeams added a commit to cbeams/dotfiles that referenced this issue Jul 16, 2014
@jdevera

This comment has been minimized.

Copy link
Contributor

commented Jul 16, 2014

@cbeams what does which vim and which vi give you?

Also, can you provide the output of:

vim --version

and

vi --version

@cbeams

This comment has been minimized.

Copy link

commented Jul 16, 2014

$ vi --version | head -1
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Dec 19 2013 15:19:49)

$ vim --version | head -1
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Dec 19 2013 15:19:49)

$ ls -l $(which vi)
lrwxr-xr-x 1 root wheel 3 Feb 18 06:44 /usr/bin/vi -> vim

$ ls -l $(which vim)
-rwxr-xr-x 1 root wheel 1472736 Feb 18 06:43 /usr/bin/vim
@jdevera

This comment has been minimized.

Copy link
Contributor

commented Jul 16, 2014

After reading the blog post in step 5, it gets even darker. To be honest I haven't got the slightest clue of what's going on 😒

@maljub01

This comment has been minimized.

Copy link

commented Aug 9, 2014

If the vim executable's name is vi, vim will run in vi mode. This is mentioned in the manpage under the option -v and seems to be causing this.

This gist proposes turning filetype on and then off to solve this issue. I have been using that solution for more than 8 months now without any issues (Ubuntu and OS X).

It might be a good idea to change the first two lines of the README's example .vimrc to:

set nocompatible              " be iMproved, required
filetype on                   " required for compatibility with Mac OS X, See issue #167
filetype off                  " required
@cameronr

This comment has been minimized.

Copy link

commented Sep 16, 2014

i spent some time looking into this and here's what's what i found out:

first, i started with just this in my vimrc:

filetype off

and the error shows up as expected:

» /usr/bin/vi --version | head -3; /usr/bin/vi -u vimrc -c q; echo $?
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Dec 19 2013 15:19:49)
Compiled by root@apple.com
Normal version without GUI.  Features included (+) or not (-):
1

that config causes vim to load ftoff.vim (you can see what files are loaded at startup by running vim --startuptime <logfile>):

" Vim support file to switch off detection of file types
"
" Maintainer:   Bram Moolenaar <Bram@vim.org>
" Last change:  2001 Jun 11

if exists("did_load_filetypes")
  unlet did_load_filetypes
endif

" Remove all autocommands in the filetypedetect group
silent! au! filetypedetect *

if you remove silent!, you can see the error that vim is generating:

» /usr/bin/vim -u vimrc -c q
Error detected while processing /usr/share/vim/vim73/ftoff.vim:
line   11:
E216: No such group or event: filetypedetect *
Press ENTER or type command to continue

setting filetype on works around the problem because it causes the filetypedetect group to exist and no error to be generated.

so why does running as vi return a non-zero exit code when vim doesn't? i didn't spend the time to trace it down exactly, but that bug was fixed somewhere in the post 7.3 patches. if you brew install vim, which currently installs 7.4.430 the problem goes away:

» /usr/local/bin/vi --version | head -3; /usr/local/bin/vi -u vimrc -c q; echo $?
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Sep 15 2014 15:48:26)
MacOS X (unix) version
Included patches: 1-430
0

so, you can resolve this issue by setting your editor to vim (instead of vi), setting filetype on before setting it off, or upgrading your version of vim.

walkerlee added a commit to walkerlee/dotfiles that referenced this issue Sep 22, 2014
@dwabyick

This comment has been minimized.

Copy link

commented Nov 1, 2014

I hit this too. The workaround git config --global core.editor $(which vim) worked for me.

dwabyick added a commit to dwabyick/dotfiles that referenced this issue Nov 1, 2014
@zhiyelee

This comment has been minimized.

Copy link

commented Dec 14, 2014

git config --global core.editor $(which vim) make sense to me

@Karunamon

This comment has been minimized.

Copy link

commented Dec 29, 2014

Confirmed here too. For whatever its worth, this happened immediately after upgrading to Yosemite. It doesn't make sense because I'm using a homebrew-installed version of vim (which lives in /usr/local) instead of the /usr/bin version provided by the OS.

sandlerb added a commit to sandlerb/dotfiles that referenced this issue Mar 15, 2015
@zyyw

This comment has been minimized.

Copy link

commented Mar 21, 2015

git config --global core.editor $(which vim)
This works in my case. Platform Mac OS X 10.9.5

coaxial added a commit to coaxial/dotfiles that referenced this issue Apr 11, 2015
jacobsa added a commit to jacobsa/dotfiles that referenced this issue May 14, 2015
Set $EDITOR to vim instead of vi.
This is an attempt to work around errors from git about the editor
failing when writing a commit message.

A tiny bit more info here:

    VundleVim/Vundle.vim#167 (comment)
    VundleVim/Vundle.vim#167 (comment)
    http://tooky.co.uk/there-was-a-problem-with-the-editor-vi-git-on-mac-os-x/
@DanielArndt

This comment has been minimized.

Copy link

commented Jun 13, 2015

Just chiming in to say this only happened to me after installing the homebrew version of vim. Worked fine before hand. Hopefully that's a hint.

Oh, and git config --global core.editor $(which vim) worked to solve the issue.

@flaing

This comment has been minimized.

Copy link

commented Jul 31, 2015

I tried git config --global core.editor $(which vim) and it doesn't work for me.

The error message are:

/usr/bin/mate -w: /usr/bin/mate: No such file or directory
error: There was a problem with the editor '/usr/bin/mate -w'.
Please supply the message using either -m or -F option.

balintk added a commit to balintk/dotfiles that referenced this issue Sep 6, 2015
jackqt added a commit to jackqt/oh-my-zsh that referenced this issue Nov 20, 2015
cappert added a commit to cappert/test that referenced this issue Feb 28, 2016
@Alhadis

This comment has been minimized.

Copy link

commented May 5, 2016

Just hit this, thank God for you guys. Solution works. :D

Like many others posting here, I'm using a version of Vim installed by Homebrew on OS/X.

The problems wouldn't be happening because Git's not reading symlinked $EDITOR paths, would it...? Homebrew executables are symlinked to /usr/bin/, sooo...

@enderahmetyurt

This comment has been minimized.

Copy link

commented Aug 29, 2016

thank you @ruebenramirez 🎉

@returnvoid

This comment has been minimized.

Copy link

commented Sep 1, 2016

git config --global core.editor $(which vim) worked for me too

@ritabugking

This comment has been minimized.

Copy link

commented Oct 8, 2016

git config --global core.editor /usr/bin/vim
solved my problem. Thanks!

@andreaswolf

This comment has been minimized.

Copy link

commented Nov 8, 2016

I had this problem repeatedly when using ":W" by error instead of ":w". Using ":w" after having used ":W" once did not fix the problem, after saving and closing, the commit message was lost.

git config --global core.editor /usr/bin/vim fixed it reliably for me.

@tdas

This comment has been minimized.

Copy link

commented Nov 9, 2016

For me setting core.editor wasnt sufficient. I had a complicated .vimrc which had the following.
filetype off
I replaced that with

filetype on
filetype off

It looks dumb but this totally worked. See @cameronr comment for more detailed explanation. Kudos to him!

@azhong00

This comment has been minimized.

Copy link

commented Apr 12, 2017

how to recover the lost git message when this happened?

@dreyks

This comment has been minimized.

Copy link

commented Apr 17, 2017

@azhong00 you can find it int .git/COMMIT_EDITMSG but only if you haven't used git commit since then

@jacwah

This comment has been minimized.

Copy link

commented Jul 28, 2017

A more general solution is to set export EDITOR=$(which vim) in your .bashrc. Git will use this environment variable if core.editor is not set and other programs will know to use Vim too.

@abdulashaka

This comment has been minimized.

Copy link

commented Sep 13, 2017

i have commit problem with my git cmd

@JDiPierro

This comment has been minimized.

Copy link

commented Aug 27, 2018

@cameronr's solution here is the best IMO. I ran into this with a git commit but then I also it hit using kubectl edit on a kubernetes resource. The git config workaround will fix the problem in git but it'll still occur in other instances that invoke an editor and use the output. Setting filetype on before setting filetype off in the .vimrc resolves it in all situations.

@wys1996

This comment has been minimized.

Copy link

commented Nov 22, 2018

this works for me too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.