HowTo: Save & Quit in VIM/VI Editor Linux!

Vim is a clone of Bill Joy’s vi text editor tool in Unix-based operating system. Vim is an editor to create or edit a text file and has a capability of powerful string manipulation. It is available for almost every operating system. There are a lot of text editor available in the Linux. Among them, Vim is one of the best terminal-based editor due to its powerful features.

In this tutorial, we will show you different ways to exit Vim text editor

Install Vim

Before starting, make sure vim is installed on your system. If not installed, run the following command to install vim:

apt-get install vim -y

Once installed, you can proceed to the next step.

Save and Exit from the vim/vi Editor

In this section, we will learn how to create a new file, add some content, save and exit from the vim/vi editor.

Let’s start with create a new file named file1.txt as shown below:

vim file1.txt

Just hit Enter to create and open the file file1.txt as shown below:


Now, pressI to insert some content. You should see the following page:


Now, press ESC to shift to the command mode and type :w and hit Enter to save the file as shown below:



You can also press ESC , type :wq or :x and hit Enter to save and exit the file as shown below:


Exit from the vim/vi Editor without Saving any Changes

Next, reopen the file file1.txt, make some changes and quit Vim without saving changes using ESC and :q key. You should receive an error as shown below:



To quit Vim forcefully without saving the file using ESC and :q! key as shown below:


Learn more about vim command

If you want to learn more about vim command. Open your terminal and run the following command:


You should see the following screen:


In short, you should remember the following commands to exit from the vim editor.

  • Esc + :w + Enter

    (Save the file)

  • Esc + :wq + Enter

    (Save and exit the file)

  • Esc + :x + Enter

    (Save and exit the file)

  • Esc + :q! + Enter

    (Exit without saving the file)

That’s it!


In the above tutorial, we learned how to exit from the vim text editor with different commands. Feel free to ask me if you have any questions.

Leave a Reply

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