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.

TLDR;

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

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.

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!

Ahh, great, there it is!

Tags:
0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments