vi editor is confusing if you’re not used to it. It takes a secret handshake to escape this application if you’ve stumbled into it. Here’s how to quit vi or vim on Linux, macOS, or any other Unix-like system.
The Quick Answer
If you’re in
vim and need to get out—with or without saving your changes—here’s how:
- First, press the Esc key a few times. This will ensure
viis out of Insert mode and in Command mode.
- Second, type
:q!and press Enter. This tells
vito quit without saving any changes. (If you do want to save your changes, type
If you want to learn the Linux command line, you’ll need to know a lot more than that. Read on and we’ll show you just how
vi works and why the instructions for quitting are so unusual.
vi is an important, powerful tool and the learning curve is worth it.
vi, The Ubiquitous Editor
vi is everywhere the chances are you’re going to run up against it. You can even find yourself inside
vi by accident. Perhaps someone asks you to look at their Linux computer for them. You issue a command like
crontab -e , and
vi pops up. Surprise, someone has configured the default editor for
crontab to be
Perhaps you’re administering a system where
vi is the only editor, or the only one that will work through a remote SSH session, and you need to edit a user’s .bashrc file.
The command to start
vi and open a file is straight forward. Type
vi , a space, and then the filename. Press Enter. The program that is launched might be
vi or it might be
vim , an ‘improved
vi‘. It depends on your Linux distribution—for example, Ubuntu uses
vim . All of the instructions in this article apply equally to
The immediately noticeable difference between
vi and other editors is that when
vi launches you can’t just start typing text. That’s because
vi is a modal editor. Editing is performed in one mode, the Insert mode, and issuing commands is performed in the Command mode.
vi launches into Command mode.
Proactive Computing found this story and shared it with you.
The Article Was Written/Published By: Dave McKay