How to Exit Vim? Multiple Ways to Quit Vim Editor

Vim editor is by far one of the most popular text editors in Linux as it is a free and open-source (OS) that helps you to create and manipulate data. Vim is widely used by professionals, programmers, and students for its power usage and flexibility when compared with other editors like Emacs or Sublime Text.

While working with vim, the essential task is to close the editor after performing changes, to proceed with other tasks. In this particular guide, we will be solely focusing on how you can quit the vim editor and what are the different ways of doing this. The content of this post is listed below:

Let’s start this guide:

Multiple Ways to Quit Vim Editor

There are different commands that you can be performed while working in a vim editor and some of them are mentioned in this article. Other than that, there are multiple ways (described below) that a user can apply to quit the vim editor:

Method 1: Use :q to Quit Vim Editor

When you open the vim application then it itself is giving you an instruction that if you want to quit the vim editor, then you can do that by pressing “:q as shown below:

One of the modes you should be aware of is the “Insert Mode,” which can be accessed by pressing the “I” key:

A user will see that after pressing this key on the keyboard, the insert is now visible at the bottom, prompting them to write anything:

When a user has finished writing and wants to quit, they need to press the “ESC”button on the keyboard.

This switches it from insert mode to command mode, allowing you to execute any command. When you press “:q” from your keyboard, you will notice that it is now displayed at the bottom, and pressing enter will quit the vim editor:

Note: Please keep in mind that this command can only be used to exit the vim editor and not to save any information that you have written in it. This is one of its main drawbacks, so if you want to save your information as well, then you need to follow our next command.

Using “:q!” Command

Also, if you made changes to an existing file, this command will not allow you to exit; in this case, type “: q!”:

Let’s head over to the second method.

Method 2: Use :wq to Exit Vim

As mentioned earlier, a user can also save every piece of information that they write in the vim editor. To do so, you need to change it to command mode and then press “:wq”:

You can add two more commands to save and quit the vim editor file, either by typing “😡” or “:x!”. So, in general, the three commands that can save and quit the vim editor are:

:wq:x:x!

We didn’t create any files in which the information could be saved, as seen in the above image, so it displays an error saying “no file name”. You can resolve this issue by first creating a file that you can do by typing:

$ vim any_filename.txt

For example, in our case:

$ vim demofile.txt

As you can see, the file name is displayed at the bottom, showing that a user can now save any information to this file. So, write anything you want by following the method described earlier and try to save and quit the file by pressing “:wq”.

  • Press the I (Insert) key from the keyboard to write anything on the vim file, and then press the “ESC button. Then, write “:wq” to save and quit the vim editor.

A user can verify this by writing “ls”, which will display all the files and folders available in the specific directory:

Alternate Ways of Quitting Vim Editor

There are some shortcut keys that will help users if they do not want to use the commands inside a terminal:

  • You can press “CTRL+Shift+Z+Q” key to directly close the vim editor.
  • The second way of quitting the vim editor is by pressing and holding “ESC” and “Shift”. After that, press the “Z” key twice.

That’s all from this guide!

Conclusion

The Vim editor is one of the most popular text editors on Linux, as it is a free and open-source (OS) that helps you to create and manipulate data. While working in a vim editor, you can come out of it using the commands “:q”, “:q!”, and “:wq” commands.

Apart from these commands, the shortcut key “CTRL+SHIFT+Z+Q” can also be used to quit vim. This Linux guide has demonstrated all the possible methods to exit from the vim editor.