Vim is a powerful text editor that developers and system administrators prefer to write/debug codes and manage systems. Vim has multiple commands and methods to do the same task such as there are different methods to exit the Vim editor.
The problem while exiting the Vim editor is that first, you have to enter into the normal mode or command mode and then type the command to exit the editor which is no less than a hassle. Furthermore, the different commands make it an even tougher experience.
Is there any easy method to save the file and exit the Vim editor? Well, yes! In this guide, I will cover how to exit the Vim editor without entering the command mode.
How Vim ZZ Key Binding is Important
What is the Difference between Vim ZZ and Vim ZQ
What is the Difference between Vim ZZ and zz
What is the Difference between Vim ZZ :x
and :wq
What is Vim ZZ
The ZZ key binding in Vim is used to exit the Vim editor. It primarily writes the file if modifications have been made and exits the Vim editor. If the multiple instances of the editor are opened then only the current instance will be closed. It is important to note that ZZ key binding is similar to :x
command.
How Vim ZZ Key Binding is Important
The ZZ key binding is advantageous because of its quick and simple usage to exit the Vim editor without typing the commands.
Various conventional methods to exit the Vim editor are listed below:
Command | Description |
:q | Close the Vim editor if no modification is made. |
:qa | Close all the files opened in the editor. |
:q! | Close the Vim editor without making the changes. |
:wq | Close the Vim editor after making changes. |
:x |
The latest versions of Vim support this command to exit the Vim editor after making changes. |
The problem with these methods is that every time you have to execute these commands you need to enter the normal mode. The ZZ shortcut eliminates this hassle and exits the Vim after making changes in the file.
How to Use Vim ZZ Key Binding
To exit the Vim editor without typing the command, simply press the SHIFT+ZZ keys.
Or, turn on the caps lock and type ZZ. Note that we have to type the capital Z letter twice, therefore, the SHIFT key is used with ZZ.
What is the Difference between Vim ZZ and Vim ZQ
Both ZZ and ZQ are key bindings in the Vim editor, not commands. As discussed in the previous sections the Vim ZZ shortcut exits the Vim editor and also saves the changes if they have been made. But if you want to exit the Vim editor without saving the changes use SHIFT+ZQ.
Or keep the caps-lock on and type ZQ.
What is the Difference between Vim ZZ and zz
The ZZ is different from zz; the zz shortcut is equivalent to z. command and brings the current line to the center of the screen. The zz key binding is used to make a better view of the current line by bringing it to the viewpoint; on the other hand, ZZ is the shortcut used to exit the Vim editor. Consider checking the caps-lock while using the zz or you may end up quitting the editor.
What is the Difference between Vim ZZ :x
and :wq
The ZZ shortcut, :x
and :wq Vim commands perform the same functionality; closing the Vim editor and saving the changes. The only difference is that the ZZ is key binding while :x
and :wq are the commands that you type in the command mode.
Conclusion
The Vim ZZ command is a Vim shortcut used to quit the Vim editor without typing the command similar to :x
and :wq. This is a simple and quick way to exit the Vim editor. If you want to exit the Vim editor without saving the file simply use the SHIFT+ZQ shortcut.