DEV Community

Cover image for How to Exit Vim
The Smart Coder

How to Exit Vim

simonholdorf profile image Simon Holdorf Originally published at ・1 min read

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)

Editor guide
natriumdev profile image

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 😉

simonholdorf profile image
Simon Holdorf Author

Ha, that made me laugh :D

webjoyable profile image

I came here just to write that :D

sandordargo profile image
Sandor Dargo

I usually push and hold down the big glowing button for 10 secs and it makes the job.

hatembentayeb profile image
simonholdorf profile image
phantas0s profile image
Matthieu Cneude

What about a hammer on the computer itself? Two to four good quality hits and the problem is solved.

mdpanf profile image

Could u make a little VIM setup manual with plugins & navigation instructions, pls🙏

darkwiiplayer profile image

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.

simonholdorf profile image
Simon Holdorf Author

That's a good idea, I will discuss that with my friends and see what we can do :)

leob profile image

Yeah most of the time it's just escape + shift-z-z for me :-)

codewithnick profile image
nikhil singh

I think !q also works not sure