How do I exit Vim when doing a Mercurial commit at the command line?
Solution 1
:q[uit]
quits.
:w[rite]
saves.
:wq
is a shortcut for both
:!command
runs a command in a shell (you could use this to commit without having to leave Vim)
Solution 2
It's also useful to know that
:q!
exits vi without saving, and Mercurial interprets that as you abandoning the checkin. This can be useful if you're editing the commit message and suddenly realise there's something else you need to do.
Solution 3
After you hit "Esc" to exit insert mode you could also type "ZZ" which will write your file to disk and quit.
Solution 4
In my case VIM tells me:
--INSERT-- recording
. Pressing ESC gives the 'error' sound on mac. Typing any kind of command has no effect whatsoever. I don't want to quit the entire terminal. Just VIM.
I had the same issue, but this worked for me (I'm on a Mac if that makes any difference).
- In Vim press Esc
- Type : - this will take you to a prompt at the bottom of terminal.
- Type q!, and then hit the Enter key.
That should take you out of Vim without saving.
What a pain in the butt.
Related videos on Youtube
Comments
-
Kenny Saunders almost 2 years
I'm on a Mac running OS X v10.6 (Snow Leopard). I have Mercurial 1.1 installed.
After I hit Esc to exit insert mode I can't figure out how to save and quit. Hitting Ctrl + C shows me instructions that say typing "quit" will write and quit, but it doesn't seem to work.
-
kevtrout over 13 yearsI was trying this myself, with no success until I read your answer and realized I should be typing the Z's as capital letters: shift +zz!
-
Allen about 13 yearsIt comes from Unix where case matters. Therefore, typing 'Z' is different from typing 'z'.
-
Admin almost 10 yearsThat exactly what i needed :)
-
Kokodoko about 9 yearsIn my case VIM tells me: "--INSERT-- recording". Pressing ESC gives the 'error' sound on mac. Typing any kind of command has no effect whatsoever. I don't want to quit the entire terminal. Just VIM.
-
Pavel almost 9 yearsthis doesnt do anything at all
-
Peter Mortensen almost 5 yearsGiven that this post is a response to a comment to an answer, perhaps justify that it qualifies as an answer to the question?