5 totally inappropriate ways to exit Vim

5 totally incorrect ways to exit Vim

The Vim text editor can seem confusing to beginners, but it's worth learning more than just how to exit.

5 totally incorrect ways to exit Vim
Image by : 

Do you know how to exit Vim?

Vim can be a challenge to learn. But for many first-time users, just exiting the program can be a problem.

Last month, the Stack Overflow blog published an article on "helping one million developers exit Vim," a testament to the then-recent milestone of a million views on a popular question on the developer help site: how to exit the Vim editor? Based on the traffic, Stack Overflow says that during peak hours on weekdays, 80 people an hour were reading about how to get out.

In fairness, if you're not familiar with Vim, getting out can be a little unintuitive. Mashing Escape, hitting Ctrl+C, typing "quit" or "exit" alone won't yield you anything. Vim does try to give you some helpful hints along the way, even showing you how to get out right when you load the program for the first time.

vim-exit.png

Unfortunately, by the time you're using a search engine to find the answer, you've probably mashed a handful of other keys on the keyboard, entered insert mode, and have no idea that you need to hit Escape to be able to enter the commands to exit. What's worse, you may have made some changes to the buffer, meaning now Vim wants you to confirm that you wish to exit without saving your changes, requiring a whole different keystroke pattern than the one you just figured out.

Further, the way many people are introduced to Vim for the first time is from the Git command-line client, when they make a commit but don't specify the commit message along with the Git command. They have no idea where they landed, what they're doing there, or how to get back out.

Vim isn't hard to learn if you're willing to commit a little time to it, and its ubiquity makes it worth the time. If you want some help, we've got 5 tips to help you get started learning Vim.

But today, in celebration of Vim's rather well-known propensity to stump casual users just trying to exit, here are five more ways to exit Vim. I recommend none of them.

Hit the x

That's right, just use your GUI to kill the whole terminal window and give up. Surely there wasn't anything else you needed that window for, anyway, and you didn't want to save any potential changes you may or may not have made to that document you had open. Technically, with a graphical version like GVim, it's not the end of the world, but if they point of Vim is to keep your finger on the keyboard, if you're using the GUI to exit you're still missing the point.

Kill it automatically

Why worry about whether you'll remember how to exit Vim after you launch it? Instead, just start it up with a built-in kill switch using timeout.

$ timeout 60s vim

Your Vim instance can be gone in sixty seconds. Hope you remembered to save!

Kill all the Vims

What do you do when any other program runs amok? You throw open another terminal and kill it. Use your preferred method: ps + kill, find it visually in top or htop, or my favorite, because it makes me sound like a renegade, killall.

$ killall -9 vim

Goodbye, Vim(s).

Close it remotely

I haven't tried this personally, but apparently, Vim's client-server capabilities mean you can access a remotely-running instance of Vim by ssh'ing in, and politely ask Vim to save your file before you exit. The Vim Wikia has full instructions. Your mileage may vary, and this may actually not be a terrible idea, if you're the sort of person who leaves unsaved changes sitting in Vim after you leave a machine—but that, itself, is probably not the best idea.

Smash your computer

No, really, please don't do this. There are better ways. But if your level of frustration is nearing that level, just head over to your favorite video or gif site and let off some steam by watching others play a real-life edition of Super Smash Brothers with their machines.

Can't wait to get out of Vim? Let us know in the comments. Of course, Emacs users don't have this problem. I assume the solution to exiting there involves switching to exit-mode and writing a little bit of Lisp to initiate exiting.

Topics

About the author

Jason Baker - Jason is passionate about using technology to make the world more open, from software development to bringing sunlight to local governments. Linux desktop enthusiast. Map/geospatial nerd. Raspberry Pi tinkerer. Data analysis and visualization geek. Occasional coder. Cloud nativist. Follow him on Twitter.