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:
- Press the ESC key in vim
- Type : in vi
- The cursor should appear at the lower left corner of the vi/vim screen
- 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.
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:
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.