How to exit Vi(m) Text Editor

Step 1

You are in command mode

Go to next step.

You are in edit mode

Hit the ESC key.

Step 2

If you want to quit without saving

Type ":q!"

If you want to save changes:

Type ":x!"

Step 3

Press Enter Key

More Information

More detailed instructions @ Stack Overflow