Monday, December 7, 2015

Re: Unintentionally closing Vim with many buffers open

On Mon, Dec 7, 2015 at 10:11 AM, Christian Brabandt <cblists@256bit.org> wrote:
> Hi wolfv!
>
> On So, 06 Dez 2015, wolfv wrote:
>
>> I usually work with one primary Vim open with multiple files in the
>> buffers list. Sometimes I will also temporarily open a few text files
>> from the file manager, each file opened in its own Vim. Then I quickly
>> close all the temporary Vims by clicking the x in the top-right
>> corner. But sometimes I unintentionally close the primary Vim with the
>> many files in the buffers list. Then I have to reopen Vim and reopen
>> all the files I was working on. Is there a way to stop me from
>> unintentionally closing Vim when the buffer list contains multiple
>> files, like a configuration or plugin that prompts "Multiple files in
>> buffers list, are you sure you want to close Vim?"
>
> Just always keep a modified buffer around. This can possibly be a hidden
> scratch buffer, whose sole purpose is to prevent a quick exit.
>
>
> Best,
> Christian

Also, don't close Vim by clicking the [X] button at top right (in the
OS-provided window decorations). Using one of the following gives you
more control:
:qa! " close Vim and discard all changes
:qa " close Vim, but not if there are changes
:xa " close Vim and save all changes
(where q stands for "quit", x stands for "exit", and a stands for "all")
The latter one will also error out if there exists a modified file
which cannot be saved, usually because it hasn't yet been named. So if
you keep one or more temporary unnamed buffer(s) with, let's say,
stuff input by means of digraphs, keymaps, etc. in order to feed it to
another program by means of the clipboard (typical temporary stuff for
me), that Vim won't be "accidentally killed": you'll have to either
use :qa! with bang (and better triple-check what you are closing
before you use that one, because it cannot be undone), or close that
particular temporary buffer with :q! (which closes nothing else,
except possibly a help buffer if these are the only two windows left,
and when you use that command you see the file being closed, it is in
the current window).

Best regards,
Tony.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment