26

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.

5 Answers 5

44

: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)

Sign up to request clarification or add additional context in comments.

2 Comments

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.
this doesnt do anything at all
22

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.

Comments

10

After you hit "Esc" to exit insert mode you could also type "ZZ" which will write your file to disk and quit.

2 Comments

I 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!
It comes from Unix where case matters. Therefore, typing 'Z' is different from typing 'z'.
2

Kokodoko's said:

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).

  1. In Vim press Esc
  2. Type : - this will take you to a prompt at the bottom of terminal.
  3. Type q!, and then hit the Enter key.

That should take you out of Vim without saving.

What a pain in the butt.

1 Comment

Given that this post is a response to a comment to an answer, perhaps justify that it qualifies as an answer to the question?
0

The top response is right. For those of you who are like me and need a little bit more details in the steps:

If it's showing --Insert-- and you can't figure out how to get out of it, first hit Esc once, then type :w to save, :q to quit without saving, :wq to do both, then hit Enter. I had to do :wq to get completely out of the file and return to the command line.

*NOTE: You have to type the ':'.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.