DEV Community

Cover image for How to exit Vim

Exit Vim How to exit Vim

Jeremy Schuurmans
I love writing clean code, and writing about code. I love building things that make people smile. I like computers, Ruby, people, music, and books.
Updated on ・1 min read

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

Discussion (22)

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.

jeremy profile image
Jeremy Schuurmans Author

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

deciduously profile image
Ben Lovy

It's rare that you would ever want to

You must be far more organized than I am. I feel like I do this all the time.

jeremy profile image
Jeremy Schuurmans Author • Edited

That's fair. I wish I was much more organized than I am. It was just drilled in me by all my teachers to never close my editor without saving, so I do it almost as a reflex. I used Atom before starting to learn Vim, and would always <Ctrl-S> before exiting, so now it's :wq all the time.

deciduously profile image
Ben Lovy • Edited

I think part of it is that I also use Vim as a quick way to just read a file, to reference it or check a value. When I do that, I want to ensure I haven't inadvertently made an edit. Vim is helpful in that it defaults to normal mode, but :q! gives me some extra peace of mind that I haven't done something dumb.

Thread Thread
jeremy profile image
Jeremy Schuurmans Author

Good point! I'll keep that in mind for the future as well. I'm looking forward to learning all the things I can do with it aside from writing code more efficiently.

sinewalker profile image
Mike Lockhart


"How do I undo in vim? Ugh. I hate vim. Stuff this, I'll do it over."

ESC :q!

goes to find a friendly editor, or SCP the file to workstation

SSHFS and VS-Code's remote extension are saving my sanity.

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

sinewalker profile image
courtjus profile image
Ghislain LEVEQUE • Edited

To exit without saving, I suggest

:!kill -9 $PPID

cmstead profile image
Chris Stead

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

jeremy profile image
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

vlasales profile image
Vlastimil Pospichal

... shell commands

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)

lizardohama profile image
jjokah profile image
John Johnson

Please can someone tell me why this rugged editor is worth using.

techysudheer profile image
Sudheer Techy

Watch cartoon for free on Watch Cartoon Online official website.

shopalino1 profile image

Super lol

Forem Open with the Forem app