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.

ADVERTISEMENTS

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.
ESC
Next, type
:q!

How to get out of VI or VIM text editor command

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:
ESC
Save the file with changes and exit Vim, enter
:wq
OR
:x
Quit the vi editor command in Linux and Unix
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

Conclusion

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 SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig 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

ADVERTISEMENTS

Comments on this entry are closed.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.