2

I am using vi editor to write scripts, however I have made a mistake deleting some lines of code without saving. Now I would like to undo the changes. The way I found to do that was to use the u keystroke to undo the changes and it worked fine.

Now I was thinking to just quit the vi editor in the current state without saving the changes so I try

  1. Press Esc key
  2. Press :q to quit

It gives me an error

No write since the last change vi error while quitting

How do I get over with this error

Thanks for help.

Shubham Khatri
  • 270,417
  • 55
  • 406
  • 400

2 Answers2

3

You need to add an exclamation mark, i.e. :q!, to force exit without saving.

LordWilmore
  • 2,829
  • 2
  • 25
  • 30
2

The error simply means the file has changed and you have not save the recent changes. Its like trying to quit MsWord without saving, it prompts a Quit without saving changes?. What you can do is

If you want to save your changes type :w and q respectively. This write you changes and quits vi.

If you want to quit without saving type q!. This will quit without saving your recent changes.

theterminalguy
  • 1,842
  • 18
  • 20