This article was originally published on The Smart Coder by Guillaume Renière
How to exit vim?
If you are in the insert mode --> press ESC to access command mode and then just type :q! + Enter
But please note that you will exit vim without saving so you should know what you are doing!
Alternatively, you can just enter ZQ on your keyboard and exit vim without saving.
Ho to exit vim and safe?
Make sure that you are not in insert mode. If you are, press ESC to enter command mode. Then you can run :wq and voila, vim will safe your changes and exit to your terminal.
Alternatively, you can just hit ZZ and vim will save and exit as well!
More useful vim commands
Now that you know how to exit vim, here are some more commands for you.
First, hit ESC to enter the command mode and leave the insert mode. You can then type in the following commands:
- :1,10wq is going to only save the lines 1 to 10 and exit
- :x can also be used for exiting vim with saving your changes
- :ex works just as :x
- :wqa will save your changes in all tabs (in case you have more than one) and exit vim
Discussion (12)
A long time ago, I came across this little joke:
How do you generate a random string?
Put a fresh student in front of vim and tell him to quit.
That was for me the trigger to learn how to quit VI 😉
Ha, that made me laugh :D
I came here just to write that :D
I usually push and hold down the big glowing button for 10 secs and it makes the job.
cool!
What about a hammer on the computer itself? Two to four good quality hits and the problem is solved.
Could u make a little VIM setup manual with plugins & navigation instructions, pls🙏
Just run
vimtutor
and you're good to go. As for plugins, just wait until you're used to the base features of vim first.That's a good idea, I will discuss that with my friends and see what we can do :)
Yeah most of the time it's just escape + shift-z-z for me :-)
I think !q also works not sure