How To Exit vi

There are a couple of ways to exist out of vi/vim inside of a unix or linux system.

Before typing any new commands you may want to press the Escape key to make sure you are in not in input mode. The first way to exit vi is

ZZ

That is, hold down shift and press the 'z' key twice. This will exit out of vi and save any changes you made if you have made any changes. Otherwise it will simply quit.

Another way to save and quit your work in vim is to enter the ex mode by pressing the colon key, and then typing 'wq' and then enter.

:wq

or :x

This will save your work and quit.

You can also quit without saving anything by typing

:q!

or

ZQ

Vi can be intimidating at first, but once you learn some of the basic commands it will begin to make sense, and then over time as you learn more advanced vi commands you will be able to edit files in a quick and efficient manner on just about any *nix system.