How do I get out of VI / VIM text editor on Linux or Unix?

I am a new Linux desktop user, and I started the vim text editor. How do I quit the vi/vim editor? How do you get out of VI / VIM text editor under Linux operating systems?

Vi and VIM (Vi Improved) is a text editor for Linux and Unix-like systems such as macOS. You can edit all sorts of files with vi. However, it is trendy among system administrators, programmers, and open source enthusiast. The vi text editor has three modes: command, input, and ex. When starting, vim begins in command mode. If you are ever unsure which mode you are in vim/vi editors, press ESC key to return to command mode.

How to get out of VI / VIM text editor

The procedure to quit the vi/vim editor is as follows:

  1. Press the ESC key in vim
  2. Type : in vi
  3. The cursor should appear at the lower left corner of the vi/vim screen
  4. Enter the following to get out of vi/vim: q!

Let us see all the commands in details.

Quit the vi editor command

To quit the vi editor without saving your files and changes. First press ESC key.
Next, type

Getting out of the VI or VIM text editor without saving your files

The above command exits the vi editor, DISCARDING any changes you have made.

How to to save a file and exit in vi / vim

Insert or delete text as per your need. Press the ESC key in vim:
Save the file with changes and exit Vim, enter

Append ! to any vim/vim command to force changes. For example, the :q! would force quit without saving and :wq! to force Vim to write the file anyway. To view changes simple using the cat command:
cat filename


This page showed how to quit/exit the vi editor with or without saving your changes. The :q! will quit the vim/vi editor, and all changes you have made to the document would be gone. However, you can do save and exit in vim too by typing :wq! or :x!. In other words, use the :wq! or :x! for save and exit purposes.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

Comments on this entry are closed.

Comments are closed. Still have questions? Post it on our forum