Vim has a reputation for being hard to quit. But it turns out there are plenty of ways to do so! Recently, I decided to do a little digging and find out just how many ways you can quit out of vim.
Here are a few (remember to always press
<Enter> after the commands).
A traditional way to quit vim is to type
:q for short. That will
work for most people.
If there are changes you’ve made but don’t care about, vim will still complain
and not let you quit. Silly vim. Just be more assertive —
What if you want to save your changes before quitting? And honestly, who
doesn’t? Tell vim to write to the file (
w) before quitting —
You’re good to go. Most people stop here and move on with their lives. But not us. We have much to learn from vim yet.
What if I could save you 33% of the typing? Well, you can save and exit with
:x. You might say, how will I remember that? Think of
both of which also work but are more typing.
Wow, we’re getting picky. Still, vim’s got your back. You only want to save the
changes made to lines 1 through 3? Sure, just type
You’re trying to save and exit from a file in a different pane or window?
Aggressive, but not a problem. Just tell vim which file you want to save and
Hmmm. That’s odd. But I suppose it’s okay.
Vim still has you covered. You can quit without saving changes with
ZQ or by
saving your changes with
ZZ. It’s like gamers saying
GG at the end
of a game, except in this case, vim’s the one winning. So
Sure. Sure it can. I know sometimes it’s just nice to be asked. Just tell vim to
confirm with you before the changes:
:confirm quit or
:conf q for short.
What if we have several windows, more panes, and even more buffers open? I just
want to quit all vim! I understand. Just tell vim to
:qa! if you don’t care about saving your changes. If you want to save your
changes, go for
:xoxo doesn’t work – vim doesn’t want a hug or a kiss.
You can also ask vim to confirm each file before it closes it with
though that really takes the rage out of rage quitting.
If you need more help, vim is there for you. Just type
:h :quit and you’ll see
all the possible options on how you can quit. Until next time!