How to quit vim / nano / any text editor on Linux

How do I quit vim?!

Has become a running gag of the computer nerd community for a few decades now, but recently I was asked by a fellow developer how to quit vim. Colour me surprised when what I saw in the terminal was not vim, but nano. After a few days of procrastination and consideration I thought it wouldn't be too much to write a post about how to quit different text editors.

Why the heck am I in a text editor?

Sometimes you'll end up in a text editor on Linux even though you really didn't ask for it. This isn't only the case when you're blackout drunk and root@production, but also when you run a git pull or git merge and get prompted for a merge message. Git will try to be helpful, but to you it might seem hell-ful to trap you in some text editor in the terminal, that you can't quit.

In this case, lots of things will help, like just killing your ssh connection, but if you want to know how to actually get out of this unscarred, read on.

How to quit vim

How to quit Vim

You can quit vim by hitting ESCAPE and then entering :q! followed by hitting ENTER. While you type :q! you should see that at the bottom of the screen.

If you want to save your changes to the file, instead type: wq. A possible error message you might get is:

E45: 'readonly' option is set (add ! to override)

This means that you don't have the correct permissions to save the file, but it is modified. To fix this, try your previous command again, but put sudo in front of it. If you don't know the sudo password, talk to your friendly system administrator.

Fun fact, the first SERP hit leads to stack overflow and has 45xx upvotes:

How to quit nano

Nano works slightly differently than vim and it doesn't have all the fancy "modes" that vim has. It's simply expecting you to hit keys in while holding down CTRL.

  • to save a file: CTRL o
  • to exit nano: CTRL x

Summary

Did this post help you? I expect you to comment or reach out otherwise ;)

Also check out these:

Tagged with: #Linux #vim

Thank you for reading! If you have any comments, additions or questions, please tweet or toot them at me!