When Vim is invoked on multiple files from the command line, then if any of those files have not been visited with :next
or via buffer switching, the :q
command pointlessly warns about the situation with a message like "43 files left to edit" and refuses to quit, even though nothing has been modified. Is there a way to eliminate this behavior?
In the :help
documentation, we have:
:q[uit] Quit the current window. Quit Vim if this is the last
window. This fails when changes have been made and
Vim refuses to abandon the current buffer, and when
the last file in the argument list has not been
edited.
If there are other tab pages and quitting the last
window in the current tab page the current tab page is
closed tab-page.
Triggers the QuitPre autocommand event.
See CTRL-W_q for quitting another window.
which just confirms the behavior: "fails ... when the last file in the argument list has not been edited".
The forced execution :q!
will work, but is not acceptable because it will discard unsaved changes.
The documentation does not seem to mention that if the command fails due to the last file not having been edited, simply repeating the command will then force it.
set confirm
? I think then you can choose to quit anyway:set confirm
, I can confirm that I like it better than:qa
, because there is no new habit to learn. You just hity
in response and you're out: same character count as:qa
. Still, I like the solution which just make:q
work. Thanks though, I will turn onconfirm
because it provides a good UX for unsaved-changes situations.confirm
option and that's it. (check_more()
inex_docmd.c
). It wouldn't be too hard to add an option for this (or expandconfirm
to accept more values) though, but that requires someone to write a patch, so if you're willing/able to spend some time on that you can fix it "properly". Other than that, there's just the workarounds you already posted.