How To Exit (Quit) Linux Vim/Vi Editor - PhoenixNAP
Maybe your like
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.
Was this article helpful?YesNoTag » How To Exit Vim Insert Mode
-
Vi Basics
-
Other Ways To Exit Insert Mode Besides Escape
-
Vim Exit From Insert Mode (Example) - Coderwall
-
How To Exit Vim – Vim Save And Quit Command Tutorial
-
Popular Vim Commands - Comprehensive Vim Cheat Sheet - KeyCDN
-
How To Exit Out Of Vim Editor - Linux Hint
-
CS107 The Vim Editor - Stanford University
-
How To Exit The Vi Or Vim Editor - How-To Geek
-
Exit Vim - Learn How To Quit Vim Three Different Ways - FactorPad
-
How Do I Switch Between Command And Insert Mode In Vim?
-
The Only Vim Insert-Mode Cheatsheet You Ever Needed
-
How To: Vi / Vim Save And Quit The Editor Command - NixCraft
-
Vim Stuck In Insert Mode - Linux - Super User
-
Custom Shortcut For 'Exit Insert Mode' Exits, But Next Key Gets 'eaten'