Is there anything wrong with opening up a new vim tab (for scratch work) while authoring a git commit?
Update: This Seems to Be a Quirk With Vi vs. Vim
On further inspection prompted by @muru's comment, it seems there are a couple of subtleties here.
EDITORenvironment variable was actually unset, so it defaulted to
vimas originally posted. Edited.
In order for vi to exit with error, it is actually important to attempt to quit first with
:q!, and this behavior can be reproduced without using tabs:
vi; echo $?
Type something in insert mode
- Attempt to quit with
:qand get the error
E37: No write since last change (add ! to override)
- Actually quit with
- Observe that the exit code is
Oddly enough, modifying the above steps by (1) using vim instead of vi, or (2) using vi but quitting with
:q!directly without using
:qfirst, yields a
0exit code instead. Both
vimhave the same exact
:versionstring on my system, so this is probably a difference in how vim behaves when started as
vion the command-line.
Original Steps with Git + Vi
Steps to reproduce:
Start making a new commit:
$ export EDITOR=vi # goes without saying :) $ git commit
Open up a new tab with
:tabeand type something. Anything.
- Switch back to the commit tab with
- Type some message, and close the commit tab with
- Now, attempt to quit the tab with
- Now, quit the scratch tab with
Recoil as vi tells you your meticulously-crafted commit message has also been discarded: 😱
error: There was a problem with the editor 'vi'. Please supply the message using either -m or -F option.
What is Git not happy with in this seemingly innocuous series of steps? 🤔
(This gets confusing because I'm testing Vim's behavior, not Vi's)
Vim's exit code indicates success when repeating the above instructions, so it's not clear why Git thinks Vim quit in error:
$ vim a-file; echo "exit code: $?" exit code: 0
^ This example is identical to how Git launches Vim, given its process entry in that state:
Also, swapping the tab exit order by closing the scratch tab first, then the commit tab, has exactly the same result.
Coming back to the million-dollar question—why is this happening? Answers in the form of snarky references to the Vim/Git docs are most welcome 😄
System: macOS High Sierra 10.13.4
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 29 2017 18:37:46)
git version 2.15.1 (Apple Git-101)