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.





Jay is the CEO and founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or draw on tablet devices. He blogs about his coding journey at http://wpguru.co.uk and http://pinkstone.co.uk.