Introduction
Vim is a Linux text editor based on the older Vi editor. Vim is an enhanced version of Vi; many commands work for both Vi and Vim.
This guide will show you how to exit in the terminal or using a shortcut key.
Note: Some Linux distributions, such as Ubuntu 18.04 and 20.04, may come with the minimal version of Vim installed. Follow our guide to install the full version of Vim on Ubuntu.
Prerequisites
- A Linux system
- Access to a terminal window / command line (Activities > Search > Terminal)
- A user account with sudo or root privileges (editing some files may require elevated privileges)
Note: If you need a test file for practicing, open a terminal window and enter vim test.txt
. Next, press the letter i
to switch to insert mode and type a few lines of text.
Exit Vim in Terminal
To issue commands in Vi/Vim, switch to command mode.
1. Press the Esc key.
2. You should see the ––INSERT––
label vanish from the lower-left.
3. To save your changes before you exit, type :w
, and then Enter. This will save any changes made. Vim will respond by outputting the filename, whether it’s new, and how many characters were written to the hard drive.
4. To exit Vi/Vim, type :q
and hit Enter.
Note: Want to personalize your Vim interface and add syntax highlighting? Learn How to Change and Use Vim Color Schemes.
Exit Vim Using a Shortcut Key
In addition to command mode, Vim also has the option for shortcut keys:
- To save a file in Vim and exit, press Esc > Shift + ZZ
- To exit Vim without saving, press Esc > Shift + ZX
More Command Options to Quit Vim
Here’s a list of commands for quitting Vim:
Esc
– switch to command mode:w
– write out changes that were made:q
– exit Vim:q!
– exit Vim and discard any changes:wq
– saves the changes, and exits Vim- :
x
– save the changes made, and exits Vim
Note: Make sure to type a colon (:
) first to signify a command. Use the Enter key to activate it.
Conclusion
You should now have several methods to exit Vi/Vim text editor. Next, learn other essential Vim commands.
Next you should also read
SysAdmin,DevOps and Development
How to Save a File in Vi / Vim & Exit
April 11, 2019
Vim (Vi IMproved) is a well-known, open-source text editor for Linux or Unix systems. It is a powerful and…
SysAdmin,DevOps and Development
How to Cut, Copy and Paste in Vim / Vi
April 6, 2020
Complete guide on how to use crucial Vim commands - copying (yanking), cutting (deleting), and pasting…
SysAdmin,DevOps and Development
How to Delete Line in Vim on Linux
April 22, 2020
Vim allows you to delete entire lines, words or characters using various Vim commands. Learn the most…
SysAdmin,DevOps and Development
How to Show or Hide Line Numbers in Vim / Vi
April 15, 2020
You can activate line numbering in Vim by showing absolute, relative or hybrid lines. Displaying or hiding…
Author
Sofija Simic
Sofija Simic is an aspiring Technical Writer at phoenixNAP. Alongside her educational background in teaching and writing, she has had a lifelong passion for information technology. She is committed to unscrambling confusing IT concepts and streamlining intricate software installations.