Instructor: Say you find yourself inside of Vim, and you want to exit. The first thing you want to try is pressing :q and then enter. That should take you out. Sometimes, you want to make changes to your files. Here, I'm making a new file, and I'm pasting in some text.
You notice at the bottom left of the screen, I am in Insert mode. That's a different mode from where we were before, which is either the X or the Command modes. To exit out of Insert mode, I have to press Escape. Then when I try to press :q again, it doesn't let me because I've made some changes to the files. It's warning me I shouldn't do that.
I can follow its instructions and just add an exclamation mark to override the warning and exit out of Vim. Then when I open up the file again, the data's gone because I didn't save it. What we can do in this case is press Escape and wq to save, as well as quit. When we go back to the original file, we can see that our changes have been saved.
There is another option, where you can ask for confirmation about the changes. Let's say I make a change to the text here. I'm going to enter in, "Hello world." Then I exit, hit :conf q and enter. It asked me if I want it changed and if I want to save it. I can say, "Yes," and then the new text will be saved when I reopen the file.
It's a common misconception that you have to be in X mode to quit. Here, I'm making a new file. I can press Shift-ZZ to save and quit, so that when I open it up again, the text persists. If you don't want your text to auto-save, you can always say Shift-ZQ.
Here, I'm going to add new text. Then I hit Shift-ZQ and it exits. When I go back to the file, you see the text doesn't persist because it wasn't saved. Now you know how to exit in both Command mode with no colons and in X mode with colons.
Sometimes, you'll be editing multiple files. In these situations, you will have multiple buffers to close. Just typing :q doesn't quite work because there's more files to close. You can keep typing :q to close them, but that gets a bit gnarly when you need to edit multiple files. Instead of typing :q multiple times, you can type :qa, and that will close all three files.
One problem with doing :qa is it doesn't save changes for you. Here, I'm doing :qa. You can see the scary error messages from before. You'd have to know to save the file to exit. If, let's say, we don't want to do that, we can actually ask for confirmations just like we did before.
Here, I'm going to add some text. I'm going to ask for confirmations as I quit all the files. Do I want to quit? Yes. That's how you exit Vim.