Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 852
Kenny Saunders Avatar asked Jun 28 '10 22:06

Kenny Saunders


People also ask

How do I save and exit Vim in terminal?

The command to save a file in Vim and quit the editor is :wq . To save the file and exit the editor simultaneously, press Esc to switch to normal mode, type :wq and hit Enter .

How do I exit Vim in terminal mac?

Other ways to exit Vim Esc + :x + Enter (Save and exit) Esc + :qa + Enter (Quit all open files) Esc + Shift ZZ (Save and exit) Esc + Shift ZQ (Exit without saving)


2 Answers

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

like image 69
zebediah49 Avatar answered Sep 20 '22 23:09

zebediah49


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.

like image 31
Norman Gray Avatar answered Sep 23 '22 23:09

Norman Gray