How to Exit Vim Editor

June 12, 2024

Introduction

Vim is a Linux text editor based on the older Vi editor. Learning how to exit Vim is important for developers, system administrators, and other IT professionals.

This guide will show you a few different ways to exit the Vim text editor.

How to Exit Vim Editor

Prerequisites

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 haven't made any changes, take the following steps to exit Vim:

1. Press the Escape key.

2. Type :q.

exit Vim without saving

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. The letter w saves the file, and the letter q exits the editor.

save and exit the file in VIm

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.

quitting Vim without saving 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?
YesNo
Sara Zivanov
Sara Zivanov is a technical writer at phoenixNAP who is passionate about making high-tech concepts accessible to everyone. Her experience as a content writer and her background in Engineering and Project Management allows her to streamline complex processes and make them user-friendly through her content.
Next you should read
How to Save a File in Vi / Vim & Exit
September 22, 2022

Vim (Vi IMproved) is a well-known, open-source text editor for Linux...
Read more
How to Cut, Copy and Paste in Vim / Vi
April 6, 2020

Complete guide on how to use crucial Vim commands - copying...
Read more
How to Delete Line in Vim on Linux
April 22, 2020

Vim allows you to delete entire lines, words or characters using...
Read more
How to Show or Hide Line Numbers in Vim / Vi
February 28, 2022

You can activate line numbering in Vim by showing absolute, relative...
Read more