DEV Community

loading...
Cover image for How to Exit Vim
The Smart Coder

How to Exit Vim

simonholdorf profile image Simon Holdorf Originally published at thesmartcoder.dev ・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)

pic
Editor guide
Collapse
natriumdev profile image
NatriumDev

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 😉

Collapse
simonholdorf profile image
Simon Holdorf Author

Ha, that made me laugh :D

Collapse
webjoyable profile image
semperlabs

I came here just to write that :D

Collapse
sandordargo profile image
Sandor Dargo

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

Collapse
hatembentayeb profile image
Collapse
simonholdorf profile image
Collapse
phantas0s profile image
Matthieu Cneude

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

Collapse
mdpanf profile image
MDPanf

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

Collapse
darkwiiplayer profile image
DarkWiiPlayer

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.

Collapse
simonholdorf profile image
Simon Holdorf Author

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

Collapse
leob profile image
leob

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

Collapse
codewithnick profile image
nikhil singh

I think !q also works not sure