Have you or a loved one ever had to reboot your computer to get out of a read-only file in VIM?
- Are you responsible for a Linux system or set of systems where a graphical editor or adding new editors is prohibited?
- Are you taking an online training course where all the labs use the VIM editor, and it’s driving you crazy?
- Do other Open Source Pros tease you about not knowing VIM?
This short tutorial will help you get past the main issues you might encounter in quitting VIM. And if you’re ready to take your VIM skills to the next level, or you want to build a true VIM foundation for future learning, there’s a dedicated multi-part course series you’ll want to check out—more on that at the end of this tutorial.
Use this tutorial to safely quit VIM, without the headaches
First off, you need to know what user you are when you edit files with VIM, so at the command line enter the id command:
IMPORTANT: One of the keys to not getting stuck in VIM is to never edit a root-only file as a regular user. If you are the system admin, look into using the sudo command to allow editing root-only files from a regular account safely!
If you are in VIM and cannot seem to quit, we’ve got your back! Relax, grab a drink of water, and let’s walk through a few very common scenarios.
You are editing a root-only file as a regular user, have made changes to the file/buffer and it won’t let you out, showing you a message like this:
Press the ESC key twice or until you hear the “error bell”, then press :qa! which will force quit all open files/buffers and take you back to the command line.
While trying to quit VIM with the keystrokes :q, you suddenly find the lower portion of your screen looks like a history list of the commands you’ve issued recently in VIM, and it freaks you out.
You have accidentally used the keystrokes q:, which opens up a Lastline or CommandLine history mode window that you could choose previous commands from to execute them again. You can close this by carefully pressing :q again, which puts you back into Command/Normal Mode and you can quit as you would normally.
You have tried to force-quit the file/buffer using :q! and suddenly you find yourself in what appears to be the command line, but it’s telling you that the q: command is not found.
You’ve flipped the keystrokes around and entered :!q, which is telling the VIM editor that you want to run an external command (:!command) and of course it won’t find the q: command, so all you get is an error! Press ENTER and you’ll be back inside VIM and can exit normally, just be careful to type exactly what you want!
Why take the full, “Text Editing with VIM” course?
Resident “VIM-ologist”, Ross Brunson is a life-long user of vi/VIM and has taught thousands of attendees how to harness its power and tame its oddities. Even if you’re a busy professional with just a few hours, this VIM course is going to be a game-changer for you. Whether you need VIM help for your next meeting or your next role, Ross has you covered with his “VIM Survival Kit”. The course comes in two distinct, but compatible sections. You can take the entire Text Editing with VIM course in around 8 hours, or give Ross 30 minutes of your time and he’ll take you through enough to confidently survive your first few editing sessions in style!
Ross has set up Text Editing with VIM to guide you through one of the most-installed, yet least understood editors.
You’ll progress from the fundamentals of what VIM is and how to get around in it, all the way to the more advanced things you can do with VIM. You’ll learn how to navigate around in VIM, change and alter text, search and replace, use VIM with External Commands to do some pretty magical things. Ross also emphasizes how to be super productive by using Windows, Tabs, and Buffers. You’ll also see some very advanced operations that would normally take you a long time to learn, but Ross utilizes Hands-on Labs to make sense of the complexities. These labs help you cement new knowledge by testing your learned skills.
We know the pain of having to reboot to exit a read-only file in VIM, and it only gets worse from there. Let Ross diagnose and prescribe the perfect course “cure”.
You’ll learn a lot, have fun in immersive labs, and enjoy spending time with one a skilled instructor who genuinely enjoys VIM, as well as helping you achieve your goals.