Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Very cool. I am using it now to write this comment!

exit

quit

exit()

ctrlC

ctrlx

stop

please exit

help exit



ESC :wq should do the trick. (Yes, I know it's a joke)


Is there a way to exit without using the ":" key?

I ask because the other day I saw a friend of mine legitimately get stuck inside vim because he coundn't type ":". The keyboard language was set to the wrong language and none of the keys would output ":" when pressed. We had to reboot the machine and find a different keyboard.


ZZ will save and exit, or ZQ to exit without saving.


Ha ha, I don't know about nowadays on Windows/Linux/MacOS (maybe someone else can comment for that), but on DOS, you could get around such issues (like a key damaged or not present) by holding down the Alt key while entering the 1- to 3-digit ASCII code for the key you wanted to enter (0-255). That was used for all kinds of tricks and jokes in those days, like entering a fake space kind of key - some ASCII code while pressing Alt - I forget which one, maybe 255. It would look like the space char on the screen - a blank - but was not the same char. Could be used to create "hidden" files that those not in the know could not access, although the file was otherwise in plain sight in DIR listings and so on :)


Ctrl-Z to suspend and then you can kill the job


Yanking the power cord usually does the trick for me too.


Even after 1.5 years of using vi at work, I still constantly get stuck trying to exit. Like I hit Ctrl+C or something, or ZZ with caps lock off, I don't even know. Then it's like "Type :quit to exit" or "Entering video mode" or "Press Shift-something to capture" and I do this random button mashing of Escape and q and ZZ that eventually gets me out, but I never know what I did.


:x is a shortcut for :wq. I wonder why nobody knows it.


:x is not only a short for :wq - the latter saves (unconditionally, even if you have saved earlier and not edited since), and then quits (the file). I was going to say that :x is also a shortcut for :q (just quit) but it is of course not a shortcut for that, since it is the same length :)

I can better describe it like this:

:x is a shortcut for telling vi/vim: save the file if not saved after last change, then quit (in either case, whether a save was needed and done just now or not) - IIRC.

Also, as others said, Shift-ZZ (when Caps Lock is off), also saves and quits (and saves one keystroke over :x - because you have to hit Enter after :x, but not after Shift-ZZ :) It is also (slightly) faster to type, since the (left) Shift key is just next to the Z key (at least on some keyboards, like mine at present).


I've never used :wq, always :x. And I've been using vim for roughly 3 years.


Sorry, I’m pretty new to vim (switched from ST this week and loving it so far). Thanks for the advice though




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: