2

:q! and ZQ both fail.

I had a file opened; I made a new tab with :tabnew (just for some register swapping); I switched back to my main file and wrote my changes to a new filename; I tried ZQ to no avail.

I then successfully closed the file (I don't recall how), leaving the extra [No name] tab open. I tried to quit again; no success. I get an error: No write since last change (add ! to override) but I am using ! already.

This is on Ubuntu 14.04 in a virtualbox.

How can I get vim to exit???


I got it to close—no idea which step worked, so I'm leaving this question open for the "why" part.

Funny behavior on the no name tab—I deleted the contents and tried to exit; got the same error message and the contents I had deleted reappeared! Used u to undo back to the oldest change (empty buffer) and tried to exit again; same error and content reappeared. Made a new tab and closed it with :q! successfully, then tried ZQ on original no-name-and-mysteriously-not-empty tab, and it somehow worked. :/

  • Do you have 'hidden' set? – Antony Jul 21 '16 at 18:31
  • @Antony I did not. But that's a good possible explanation. – Wildcard Jul 21 '16 at 18:32
  • Hmm, well I can't reproduce the problem. Can you try to remember your steps and come up with a reproducible example? – Antony Jul 21 '16 at 18:39
2

From :help abandon:

Vim remembers whether you have changed the buffer. You are protected from losing the changes you made. If you try to quit without writing, or want to start editing another file, Vim will refuse this. In order to overrule this protection, add a '!' to the command. The changes will then be lost. For example: ":q" will not work if the buffer was changed, but ":q!" will. To see whether the buffer was changed use the "CTRL-G" command. The message includes the string "[Modified]" if the buffer has been changed.

If you want to automatically save the changes without asking, switch on the 'autowriteall' option. 'autowrite' is the associated Vi-compatible option that does not work for all commands.

If you want to keep the changed buffer without saving it, switch on the 'hidden' option. See hidden-buffer. Some commands work like this even when 'hidden' is not set, check the help for the command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.