How to quit vi without saving your changes

It just occurred to me that even though I know my way around vi fairly well, I never had to quit it without saving my changes. Usually I just go back in and overwrite my mistakes.

Today I did something though that wasn’t as easy to eliminate: instead of pasting an IP address, I accidentally pasted a 4000+ character stylesheet. Dang!

So how do we leave vi and NOT save our changes? Here’s how:

  • press ESC to exit editing mode (insert/append/whatever)
  • press : (the colon character)
  • enter q!

Now you’re back on the command line without any saved changes.

Remind me: how do we SAVE changes again?

There are several ways of doing this, but my personal favourite is this:

  • press ESC to exit editing mode (insert/append/whatever)
  • press SHIFT + Z twice

This will put you back on the command line and your changes are saved.

About Jay Versluis

Jay is a medical miracle known as a Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

Add your voice!