8 Methods to Exit Vim Editor in Linux

How To Exit Vim Ubuntu Featuredhttps://www.maketecheasier.com/assets/uploads/2019/04/how-to-exit-vim-ubuntu-featured-200x100.jpg 200w, https://www.maketecheasier.com/assets/uploads/2019/04/how-to-exit-vim-ubuntu-featured-400x200.jpg 400w" class="extendsBeyondTextColumn" style="max-width: none; margin: auto; display: block; height: auto; clear: both; width: 800px; -webkit-margin-start: -62.703125px;">

Vim is known as an incredibly powerful text editor but is equally well-known for its steep learning curve. If you frequently work on the command line, it’s worth learning at least some of the basic functionality. Unfortunately, if you don’t take the time to learn it, even something as simple as exiting Vim can be difficult.

Normal keyboard shortcuts won’t help you here. Nothing you’ve learned in your entire computing life will help you, in fact. Vim is very much its own creature, and even to exit it, you’re going to have to learn how to do things the Vim way.

 

Accidentally Launch Vim? Here’s How to Get Out Fast

If you meant to run another command but accidentally launched Vim instead, exiting is fairly simple. Vim launches in what it calls “Normal mode,” which means you’re not actually editing the file. Anything you type will be interpreted as a command.

First, you’ll need to type the : key, followed by the letter q to quit. To get out of Vim, type the following:

:q

If you get an error that says “No write since last change (add ! to override),” you accidentally entered text or changed a file. Type the following instead:

:q!

 

How To Exit Vim Ubuntu Simple Quit

Stuck in Insert Mode?

You might have tried to quit by typing a few different letters and accidentally ended up in Vim’s Insert Mode. This is where you actually type new text into a file. Once you’re in this mode, you may not know how to get out. In this case, the above tips won’t help you.

Fortunately, the key to getting out of Insert Mode is simple. Just hit the Escape key. This will return you to Normal Mode and let you use the above instructions to quit the editor.

How to Quit without Saving

It’s possible you launched Vim on purpose, started to edit a file, and now you’re in over your head. If you’ve made changes to the file and don’t want to keep them, it’s simple to quit without saving.

We already mentioned one option for quitting without saving above:

:q!

If you’ve opened multiple files and want to quit all of them at once without saving, this is easy too. Just type the following:

:qa!

How to Save Your Files and Exit

Maybe you’ve made changes and want to keep them. Fortunately, this is just as easy as quitting without saving. You just need to add w to your command. Try the following:

:wq

If you prefer shorter commands, the following will also save and quit:

:x

Other Methods for Exiting Vim

There are a few other ways to quickly quit Vim. First, hit the Escape key to make sure you’re not in insert mode.

Holding down the Shift key and hitting ZZ will save and quit.

Holding down Shift and hitting ZQ will quit without saving.

 

Want to Learn How to Use Vim?

As we mentioned at the top of the article, Vim is powerful and well worth knowing. Even if it seems intimidating at first, knowing the editor can be very useful down the road. That said, you may not be sure where to start.

Fortunately, we can help you in your journey toward learning and eventually mastering Vim. You can start with our beginner’s guide to using Vim. This is the first in a multi-part series that can take you a long way toward getting the most out of the Vim editor.