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:
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.