Vim is a core text editor for any IT professional working with Linux, built on the original Vi program. It is pre-installed on every distribution and accessible over SSH, making it the tool developers and system administrators use for quick file edits and configuration changes.
While Vim offers immense power, learning the essential commands is a prerequisite for anyone who interacts with a Linux server.
This guide will show you a few different ways to exit the Vim text editor.

Prerequisites
- A Linux system (this tutorial uses Ubuntu 22.04).
- Command-line access.
- Vim installed.
Exit Vim Using Esc Key
Vim operates in different modes, each with a distinct purpose and set of commands. To exit Vim, the editor needs to be in Normal mode. To switch to Normal mode, press the Escape key. When switching from Insert mode, you should see the โโINSERTโโ label disappear from the lower-left corner.
Exit Vim without Saving Changes
If you made no changes, take the following steps to exit Vim:
1. Press the Escape key.
2. Type :q.

3. Hit Enter.
The system exists Vim and brings you back to the command line.
Exit Vim and Save Changes
To save changes and exit the editor, take the following steps:
1. Press the Esc key.
2. Type :wq. Including w ensures Vim saves the file, while q exits the editor.

3. Hit Enter.
Note: If you want to personalize your Vim interface and add syntax highlighting, learn how to change and use Vim color schemes.
Exit Vim and Discard Changes
If you have made changes using Vim but want to discard them, take the following steps:
1. Press the Escape key.
2. Type :q!. The q stands for quit, and the ! forces Vim to discard any changes.

3. Hit Enter.
Conclusion
This article explained several ways to exit the Vim text editor, depending on whether you want to save or discard the changes.
Next, learn other essential Vim commands.



