How do I exit Vim when doing a Mercurial commit at the command line?

60,235

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

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.

Share:
60,235

Related videos on Youtube

Kenny Saunders
Author by

Kenny Saunders

designer / developer / musician

Updated on July 09, 2022

Comments

  • Kenny Saunders
    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
    kevtrout over 13 years
    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!
  • Allen
    Allen about 13 years
    It comes from Unix where case matters. Therefore, typing 'Z' is different from typing 'z'.
  • Admin
    Admin almost 10 years
    That exactly what i needed :)
  • Kokodoko
    Kokodoko about 9 years
    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.
  • Pavel
    Pavel almost 9 years
    this doesnt do anything at all
  • Peter Mortensen
    Peter Mortensen almost 5 years
    Given that this post is a response to a comment to an answer, perhaps justify that it qualifies as an answer to the question?