2

The "old" Vim behavior was to close the file when all associated buffers are closed. With the newest version of Neovim, it appears that closing a buffer doesn't actually close the file. As well, closing an unsaved buffer doesn't prompt to save the file first, unless :qa is used or it's the last open buffer, etc.

Not sure what changed, but I absolutely hate this behavior as it disrupts my workflow pretty extensively when I bump into it. Is there a way to disable this behavior in favor of the old behavior?

4
  • 1
    You might be talking about the 'hidden' option, but note that vim doesn't really have a concept of "closing files." There are only buffers, windows, and tabs. You also don't close a buffer: you can load, view, modify, write, unload, delete, and wipe them. With that, it's hard for me to understand what you're asking.
    – D. Ben Knoble
    Commented Jun 28, 2022 at 18:43
  • When I :q a buffer, vim seems to just hide the buffer instead of closing it. And in this case, it also keeps the swap file intact so other vim processes trying to open the file show the warning about the swap file existing. Commented Jun 28, 2022 at 23:01
  • You don't close buffers. See :help windows.txt and around :help hidden-buffer. You can completely get rid of a buffer (:bunload, :bdelete, :bwipeout). One or more of those should help get rid of the swap file, at least.
    – D. Ben Knoble
    Commented Jun 29, 2022 at 19:27
  • cf. vimcasts.org/episodes/working-with-buffers
    – D. Ben Knoble
    Commented Jun 29, 2022 at 19:30

1 Answer 1

2

From :help :q


:q[uit]
:{count}q[uit]                      *:count_quit*
CTRL-W q                        *CTRL-W_q*
CTRL-W CTRL-Q                       *CTRL-W_CTRL-Q*
        Without {count}: Quit the current window.  If {count} is
        given quit the {count} window.
                            *edit-window*
        When quitting the last edit window (not counting help or
        preview windows), exit Vim.

        When 'hidden' is set, and there is only one window for the
        current buffer, it becomes hidden.  When 'hidden' is not set,
        and there is only one window for the current buffer, and the
        buffer was changed, the command fails.

        (Note: CTRL-Q does not work on all terminals).

        If [count] is greater than the last window number the last
        window will be closed: >
            :1quit  " quit the first window
            :$quit  " quit the last window
            :9quit  " quit the last window
                " if there are fewer than 9 windows opened
            :-quit  " quit the previous window
            :+quit  " quit the next window
            :+2quit " quit the second next window
<
        When closing a help window, and this is not the only window,
        Vim will try to restore the previous window layout, see
        |:helpclose|.

Emphasis on

        When 'hidden' is set, and there is only one window for the
        current buffer, it becomes hidden.  When 'hidden' is not set,
        and there is only one window for the current buffer, and the
        buffer was changed, the command fails.

So the solution sounds like you want the :set nohidden behavior.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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