vi editor is confusing if you are not used to it. A secret handshake is required to avoid this application if you find it. To stop vi or vim on Linux, macOS, or another Unix-like system.
The Quick Response
If you are in
vim and proceed with or without saving the changes:
- First, press the Esc Button a few times. This ensures that
viis not in insert mode and command mode.
: q!and press Enter. This instructs
vito quit the program without saving any changes. (If you want to save the changes, enter
If you want to learn the Linux command line, you need to know much more. Read on and we'll show you how
vi works and why the instructions to quit are so unusual.
vi is an important, powerful tool, and the learning curve pays off.
vi, The Ubiquitous Editor
vi is the chance that you will run into it everywhere. You can even find yourself by accident in
vi . Maybe someone asks you to take a look at their Linux computer. They issue a command such as
crontab -e and
vi . Surprise, somebody has configured the default editor for
You may be managing a system where
vi is the only editor The only one that works through a remote SSH session, and you need to edit a user's .bashrc file.
The command to start
vi and to open a file is straightforward. Enter
vi a space and then the file name. Press Enter. The program started could be
vi or it could be
vim an "improved
vi ". That depends on your Linux distribution. For example, Ubuntu uses
vim . All instructions in this article apply equally to
The immediately noticeable difference between
vi and other editors is that vi
vi vi vi is not is possible Start by entering the text. That's because
vi is a modal editor. The editing is done in a mode, the insert mode, and the output of instructions is executed in the command mode.
vi starts in command mode.
Unfamiliar with the concept of insert mode and command mode, this can be confusing. Many commands that you can execute in command mode affect the file you entered. If you are in command mode but are accidentally trying to enter text into your file, it will not end well. Some of the keystrokes you issue are recognized as commands. These commands tend to delete or split lines, move the cursor or delete text.
Regardless of what you type, you can not find a way to quit or quit the editor. By now, your file is pretty mangled and the seemingly random beeps are driving you nuts.
Command Mode and Insert Mode
You must toggle
vi into the appropriate mode for what you are trying to achieve.
The command mode is the default mode when
vi is started. If you do not know better, you will try to type. If you press the & # 39; i & # 39; key or any of the other 10 keys that call insert mode (a, a, c, c, i, o, o, r, s, and s) You suddenly see what happens you write. You are now in insert mode.
This may sound like progress until you press one of the arrow keys. In this case, A, B, C, or D appear as a single letter in an otherwise blank new line. Top of the file.
It's okay, we have your back. This is surprisingly easy if you know how. Note the two keystrokes: Press Esc to enter the command mode and "i" enter the insert mode.
You must be in command mode and enter the correct command to exit the editor.
From Command Mode to Security
To enter command mode, press the Esc key. Nothing visible will happen. Hit it a few more times. If you hear a beep when you press the escape key, you are in command mode. The beep tells you, "Stop pressing Esc, you're already in command mode." If you press Esc, we're fine.
Enter a colon, the letter "q" and an exclamation point, without spaces. These three characters should be displayed at the far left of the bottom line of the terminal. If it does not, press Esc until you hear a beep and try again. Press Enter if you can see it:
In this command
q is an abbreviation for
quit . The exclamation point adds highlighting so you can
vi "Quit!" Call. Maybe you feel a little better.
The exclamation point also points to
vi through and not to save the changes that you may have made to the file. If you've been fooling around in
vi and you do not know what you're doing, you probably do not want to save the devastation you've done.
Once you are back at the command line you may want to check again if the file has not been changed. You can do this with the following command:
cat .bashrc | less
If you exit
vi and a message appears with the message "No writing since the last change", it means that you have the exclamation point of the command missed .
vi gives you the chance to end your changes and lose any changes you may want to keep. Just put the command
: q! with the exclamation point to leave the command
vi and discard any changes.
 If you are sure save your changes
If you are satisfied with the changes that you have made to your file, you can use
quit and save: wq (write and command quit). Make sure that you are absolutely sure that the screen changes should be written to the file before proceeding.
Enter a colon, the letter w (writing), and the letter q (quit). Press ENTER if you can see it in the lower left corner of the terminal:
The learning curve is worth it
vi It's a bit like using a piano. You can not just sit down and use it. You have to practice something. To sit down and try to learn on the fly, if you are under pressure to work something, is not the way to go. It also makes sense to sit down at a piano for the first time as the curtain rises for your opening concert.
Much of the power of
vi comes from its numerous keyboard shortcuts, each one performing a common editing task. That's great, but you can not benefit from them until you memorize them, and they're part of your muscle memory.
Until then, if you find yourself
vi and look at an important file, just
: q! and leaving the process. Your important file will thank you.