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.
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.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
|Category||List of Unix and Linux commands|
|Firewall||Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04|
|Network Utilities||dig • host • ip • nmap|
|OpenVPN||CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04|
|Package Manager||apk • apt|
|Processes Management||bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time|
|Searching||grep • whereis • which|
|User Information||groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w|
|WireGuard VPN||Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04|