Git commit in terminal opens VIM, but can't get back to terminal
Solution 1
To save your work and exit press Esc and then :wq (w for write and q for quit).
Alternatively, you could both save and exit by pressing Esc and then :x
To set another editor run export EDITOR=myFavoriteEdior
on your terminal, where myFavoriteEdior
can be vi
, gedit
, subl
(for sublime) etc.
Solution 2
not really the answer to the VIM problem but you could use the command line to also enter the commit message:
git commit -m "This is the first commit"
Solution 3
You need to return to normal mode and save the commit message with either
<Esc>:wq
or
<Esc>:x
or
<Esc>ZZ
The Esc key returns you from insert mode to normal mode. The :wq, :x or ZZ sequence writes the changes and exits the editor.
Solution 4
Simply doing the vim "save and quit" command :wq
should do the trick.
In order to have Git open it in another editor, you need to change the Git core.editor
setting to a command which runs the editor you want.
git config --global core.editor "command to start sublime text 2"
Solution 5
This is in answer to your question...
I'd also like to know how to make it open up in Sublime Text 2 instead
For Windows:
git config --global core.editor "'C:/Program Files/Sublime Text 2/sublime_text.exe'"
Check that the path for sublime_text.exe
is correct and adjust if needed.
For Mac/Linux:
git config --global core.editor "subl -n -w"
If you get an error message such as:
error: There was a problem with the editor 'subl -n -w'.
Create the alias for subl
sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
Again check that the path matches for your machine.
For Sublime Text simply save cmd S
and close the window cmd W
to return to git.
Related videos on Youtube
Leon Gaban
Investor, Powerlifter, Crypto investor and global citizen You can also find me here: @leongaban | github | panga.ventures
Updated on March 14, 2020Comments
-
Leon Gaban about 4 years
Trying to learn GitHub at the moment and doing this Git essentials tutorial over at nettuts. I'm on the lesson about making commits.
The teacher types
git commit
and it opens VIM as his editor (I'd also like to know how to make it open up in Sublime Text 2 instead) anyways it opens in VIM and I add in 1 line saying this is my first commit and hit save.Next it then prompts me to save the output to the desktop, something I did not see in his screencast. Now I'm still in VIM and not sure how to get back to 'normal' terminal :(
I couldn't figure it out so I just exited the terminal and relaunched it, did git commit again and had some warning messages about duplicates! Not sure if I need to
(E)edit
anyways or(A)abort
.git status
vim
message when I reopen terminal and do git commit again
-
guido over 11 yearsf you just want to know how to save and exit vim, it's :wq
-
Tim Moore almost 10 yearspossible duplicate of Using git commit -a with vim
-
Kokodoko almost 9 yearssame problem here... as soon as I try to commit, the terminal opens some kind of editor that I can't quit out of. Very annoying!
-
Leon Gaban almost 9 years@Kokodoko yeah I just commit with
git commit -m 'my message'
now, that's it :) no need for an editor, never needed to use 1, only needed 1 liners. -
liamvictor almost 9 years@LeonGaban short commit messages are okay for the first commit but from them on you should try to adopt the technique of having a short subject and then detailing what actually happened in that commit.
-
baydi over 8 years@LeonGaban you are amazing
-
chharvey over 7 years
-
-
Lieven Keersmaekers over 11 years+1 on explaining the command sequence and in the process showing how to switch editors if needed (but seriously, why would anyone want to use an editor other than vim :)
-
Xavier over 11 yearsN.B. A simple
:x
save and quit vim it's a bit faster than:wq
;) -
Machta about 10 yearsTe set the editor permanently you can use: git config --global core.editor myFavoriteEditor
-
Eric almost 10 yearsThanks for the tip on setting the editor to sublime text. I did run into one problem though, I had to set a
--wait
flag:git config --global core.editor "subl --wait"
. This preventsAborting commit due to empty commit message.
-
Millie Smith about 9 years
:q!
if you don't want to save your changes. -
Kokodoko almost 9 yearsNope... not working. Terminal asks for a commit message but no key command in the world will quit out of the text editor.
-
Kokodoko almost 9 yearsNope... the esc key does nothing. I am stuck in "Merge branch master of ..." Please enter a commit message to explain why this merge is necessary.
-
Lieven Keersmaekers almost 9 yearsDid you enter a commit message? What happens when you press
<Esc>:wq
? -
oyalhi over 8 yearsIn my case nothing happens. What is this cryptic commands, is this 2016 or 1996?
-
oyalhi over 8 yearsesc key does nothing for me. What is this cryptic commands, is this 2016 or 1996? Incredible...
-
Lieven Keersmaekers over 8 years@Homo-Erectus - I started using vim some 4 years ago and my only regret is I didn't started earlier. I don't consider it time wasted, you should try it. It does have a steep learning curve mind you but it will be well worth it. As for the commands, I don't have much to add. Type <esc>, type :, type x and that should be it.
-
Allison Wilson about 7 yearsTHANK YOU SO MUCH, I didn't realize I had to actually press the damn colon key on my keyboard to start typing the commands. That is massively confusing.
-
Anatoly Yakimchuk about 7 years@oyalhi It is never late to start using vim
-
Dave Kielpinski about 7 yearsTotally doesn't work. Yes I entered a commit message. Vim sucks.