Skip to content

How to exit Vim

If only I had a dollar for every time I saw someone sitting at their computer, trying for the life of them to exit vim

To save and exit; press : followed by x and then hit Enter to save and exit the file in vim.


Vim or sometimes just vi is a command-line (cli) application that lets you edit documents. It’s massively popular and my personal go-to editor when I’m on a Linux box. Particularly if I’m editing remote files on a webserver or other.

Let’s say that we have a really important file that we need to edit:

$ ls a_really_important_file.txt
Code language: Bash (bash)

To use vim to view this file, we’d just do an obvious vim a_really_important_file.txt

This would drop us into the file right away.

Ok, so we now press i on the keyboard to enter edit mode.

We can now add our super important text

To save this document and exit out of vim, we will start by pressing esc to take us out of edit mode.

We know this worked because it will no longer say --INSERT-- at the bottom anymore.

To save and exit; press : followed by x and then hit Enter to save and exit the file in vim.

If you don’t want to save the file, you can press : followed by q! and then hit Enter to exit vim leaving the file as it was.

If you only want to save what you’ve been doing, but not exit vim, then type : followed by w and then hit Enter to leave you where you are.

See also  How to Extract the Files in a Docker Image

Now that we’ve saved and exited vim, let’s make sure that the file was actually written after all:

$ cat a_really_important_file.txt The answer to the universe is definitely not [email protected]* I tried it on a friend and it didn't solve anything!
Code language: Bash (bash)

Ahh, great, there it is!

Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x