

Just reissue the :q! command with the exclamation point in place to exit from vi and abandon any changes. To prevent you quitting and losing any changes you might wish to keep, vi is giving you the chance to save them. When you are exiting vi, if you see a message saying “no write since last change,” it means you missed the exclamation point off the command. You can do this with the following command: cat. Once you’re back at the command line you might want to double-check to make sure the file hasn’t been altered. If you’ve been blundering about in vi and not knowing what you’re doing you probably don’t want to save the havoc you’ve wreaked. The exclamation point also instructs vi to not save any of the changes you may have made to the file. That might make you feel a little better. The exclamation point adds emphasis, so it’s like you’re shouting “Quit!” at vi. In this command q is an abbreviation for quit. Press the Enter key when you can see them: :q! If they don’t, hit Esc until you hear a beep, and try again. These three characters should appear at the far left of the bottom line of the terminal. Type a colon, the letter “q,” and an exclamation point, without any spaces. The beep is telling you “Stop pressing Esc, you’re in Command mode, already.” If you hear a beep when you hit Esc, we’re good. If you hear a beep when you hit the Escape key, then you’re in Command mode. You need to be in Command mode, and to enter the correct command to leave the editor. Remember these two keystrokes: Esc takes you to Command mode and “i” takes you to Insert mode. This is surprisingly easy when you know how. If you do that, A, B, C, or D will appear as the only letter on an otherwise blank new line. This might feel like progress until you hit one of the arrow keys. If you happen to hit the ‘i’ key, or any of the other 10 keys that invoke Insert mode (a, A, c, C, I, o, O, R, s, and S) you’ll suddenly see what you’re typing. Unless you know better, you’ll start trying to type. You need to switch vi into the appropriate mode for what you’re trying to accomplish.Ĭommand mode is the default mode when vi launches. Meanwhile, your file is getting pretty mangled and the seemingly random beeps are driving you crazy.

Those commands are liable to delete or split lines, move the cursor around, or delete text.Īnd, no matter what you type, you can’t find a way to exit or quit from the editor. Some of the keystrokes you issue will be recognized as commands. If you are in Command mode but you’re mistakenly trying to type text into your file, it isn’t going to end well. A great many of the commands that you can issue in Command mode affect the file you’re typing. If you’re unfamiliar with the concept of Insert mode and Command mode, it can be baffling. Editing is performed in one mode, the Insert mode, and issuing commands is performed in the Command mode. The immediately noticeable difference between vi and other editors is that when vi launches you can’t just start typing text. All of the instructions in this article apply equally to vim. It depends on your Linux distribution-for example, Ubuntu uses vim. The program that is launched might be vi or it might be vim, an ‘improved vi‘. Type vi, a space, and then the filename. The command to start vi and open a file is straight forward. 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. Surprise, someone has configured the default editor for crontab to be vi. You issue a command like crontab -e, and vi pops up. Perhaps someone asks you to look at their Linux computer for them. You can even find yourself inside vi by accident. vi, The Ubiquitous Editorīecause vi is everywhere the chances are you’re going to run up against it. vi is an important, powerful tool and the learning curve is worth it. Read on and we’ll show you just how vi works and why the instructions for quitting are so unusual. If you want to learn the Linux command line, you’ll need to know a lot more than that. (If you do want to save your changes, type :wq instead.) This tells vi to quit without saving any changes. This will ensure vi is out of Insert mode and in Command mode. If you’re in vi or vim and need to get out-with or without saving your changes-here’s how:
