Skip to content

BUG: close_if_last_window does not work when discarding changes #1931

@N1ckx

Description

@N1ckx

Did you check docs and existing issues?

  • I have read all the docs.
  • I have searched the existing issues.
  • I have searched the existing discussions.

Neovim Version (nvim -v)

v0.12.0

Operating System / Version

Ubuntu 24.04

Describe the Bug

With neotree visible on screen and close_if_last_window set to true if I modify a file and then try to discard changes and exit with :q! neotree does not close and this warning appears instead:

[Neo-tree WARN] Cannot close because one of the files is modified. Please save or discard changes

Now if I do :q again i get an error:

[Neo-tree ERROR] debounce  filesystem_navigate  error:  .../nvim/site/pack/core/opt/nui.nvim/lua/nui/split/init.lua:169: Lua: .../nvim/site/pack/core/opt/nui.nvim/lua/nui/split/init.lua:170: BufEnter Autocommands for "*": Vim(split):E242
: Can't split a window while closing another                                                                                                                                                                                                 
stack traceback:                                                                                                                                                                                                                             
        [C]: in function 'nvim_command'                                                                                                                                                                                                      
        .../nvim/site/pack/core/opt/nui.nvim/lua/nui/split/init.lua:170: in function <.../nvim/site/pack/core/opt/nui.nvim/lua/nui/split/init.lua:169>                                                                                       
        [C]: in function 'nvim_win_call'                                                                                                                                                                                                     
        .../nvim/site/pack/core/opt/nui.nvim/lua/nui/split/init.lua:169: in function '_open_window'                                                                                                                                          
        .../nvim/site/pack/core/opt/nui.nvim/lua/nui/split/init.lua:257: in function 'mount'                                                                                                                                                 
        ...pack/core/opt/neo-tree.nvim/lua/neo-tree/ui/renderer.lua:1192: in function 'acquire_window'                                                                                                                                       
        ...ree.nvim/lua/neo-tree/sources/filesystem/lib/fs_scan.lua:627: in function 'get_items'                                                                                                                                             
        ...t/neo-tree.nvim/lua/neo-tree/sources/filesystem/init.lua:176: in function '_navigate_internal'                                                                                                                                    
        ...t/neo-tree.nvim/lua/neo-tree/sources/filesystem/init.lua:197: in function <...t/neo-tree.nvim/lua/neo-tree/sources/filesystem/init.lua:196>                                                                                       
        [C]: in function 'pcall'                                                                                                                                                                                                             
        .../pack/core/opt/neo-tree.nvim/lua/neo-tree/utils/init.lua:125: in function 'debounce'                                                                                                                                              
        ...t/neo-tree.nvim/lua/neo-tree/sources/filesystem/init.lua:196: in function 'navigate'                                                                                                                                              
        .../core/opt/neo-tree.nvim/lua/neo-tree/sources/manager.lua:615: in function 'navigate'                                                                                                                                              
        ...ack/core/opt/neo-tree.nvim/lua/neo-tree/command/init.lua:194: in function 'do_show_or_focus'                                                                                                                                      
        ...ack/core/opt/neo-tree.nvim/lua/neo-tree/command/init.lua:164: in function 'execute'                                                                                                                                               
        ...ack/core/opt/neo-tree.nvim/lua/neo-tree/command/init.lua:171: in function '_command'                                                                                                                                              
        ...vim/site/pack/core/opt/neo-tree.nvim/plugin/neo-tree.lua:7: in function <...vim/site/pack/core/opt/neo-tree.nvim/plugin/neo-tree.lua:6>

Screenshots, Traceback

No response

Steps to Reproduce

  1. Set close_if_last_window to true in neotree configuration
  2. Open a file in neovim
  3. Toggle neotree. I use :Neotree filesystem show left
  4. Edit the file
  5. Exit with :q!

Expected Behavior

Neotree should close cleanly. Note that:

  1. If close_if_last_window is set to false i can close the buffer with :q! and then close neotree with another :q without issues but i want it to be automatic
  2. :qa! always works without issues

Your Configuration

vim.pack.add{
  -- Tree
  {
    src = 'https://github.com/nvim-neo-tree/neo-tree.nvim',
    version = vim.version.range('3')
  },
  'https://github.com/nvim-lua/plenary.nvim',
  'https://github.com/MunifTanjim/nui.nvim',
  'https://github.com/nvim-tree/nvim-web-devicons',
}

require('neo-tree').setup({
  close_if_last_window = true
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions