DEV Community

Cover image for How to exit Vim
Jeremy Schuurmans
Jeremy Schuurmans

Posted on • Edited on

Exit Vim How to exit Vim

To exit Vim:

  1. If you are in edit mode, first press the esc key.
  2. Then enter :wq + return to save and exit.

To exit without saving, you can run :q! + return

Latest comments (18)

Collapse
 
jjokah profile image
John Johnson Okah

Please can someone tell me why this rugged editor is worth using.
I find it COOL but FRUSTRATING.

Collapse
 
sinewalker profile image
Mike Lockhart • Edited

I wish I could find the original where I saw this...

Gandalf, reading a battered old file from the server:

They have taken the bridge… and the second hall.
We have barred the gates… but cannot hold them for long. The ground shakes.
Drums… drums… in the deep
:wq :w :q!
A shadow moves in the dark
:x :x! :quit :help
^Z ^C ^X ^[^[x ^D
We cannot get out. They are coming

Collapse
 
cmstead profile image
Chris Stead

I was taught to pronounce :wq as "write and quit" and :q! As "quit, dammit". 😊

Collapse
 
jeremy profile image
Jeremy Schuurmans

😂

Collapse
 
matthew_collison profile image
Matthew Collison • Edited

It's day 728

I'm still stuck in Vim

With 2.54839e30 possible key-press combinations, it has become evident that my human typing capabilities alone are not going to brute force the phrase that will allow my exit

I am now on the 7th revision of my quantum computer program in an attempt to solve this issue

Send help

Collapse
 
sinewalker profile image
Mike Lockhart

😂

Collapse
 
flexdinesh profile image
Dinesh Pandiyan

To remember when to use :wq and :q! without getting confused, I always say it out loud.

wq = write (to disk) and quit
q! = quit without writing (to disk)

Collapse
 
lizardohama profile image
lizard_ohama • Edited

:saveas filename

Collapse
 
vlasales profile image
Vlastimil Pospichal

Ctrl-Z
... shell commands
fg

Collapse
 
courtjus profile image
Ghislain LEVEQUE • Edited

To exit without saving, I suggest

:!kill -9 $PPID

Collapse
 
gypsydave5 profile image
David Wickes

Come now, we're just scratching the surface...

Given you're in command mode:

  • :wqa will write, quit all buffers (in case you have more than one)
  • :x will also save and quit
  • :ex as above
  • ZZ will save and quit
  • ZQ will just quit
  • :1,5wq will save only lines 1 to 5 and quit

There's more. A lot more. Interested? :h quit will take you to the Vim help section on quitting.

Collapse
 
jeremy profile image
Jeremy Schuurmans

Haha! Absolutely! I was hoping for comments just like this. Thank you, and keep the Vim tricks coming!

Some comments may only be visible to logged-in visitors. Sign in to view all comments.