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.

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post

How to Make Website WCAG Compliant?

Next Post

Link download Kali Linux 2020.1 (ISO + Torrent)

Related Posts