- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 630
Closed
Labels
PR pleasenvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciatednvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciateddocumentationImprovements or additions to documentationImprovements or additions to documentation
Description
Description
Without any configuration, neovim simply doesn't quit as nvim-tree is the last buffer. Many people suggest, as is also mentioned in the README.md (#1115 ), that I should add following command:
vim.api.nvim_create_autocmd("BufEnter", {
nested = true,
callback = function()
if #vim.api.nvim_list_wins() == 1 and vim.api.nvim_buf_get_name(0):match("NvimTree_") ~= nil then
vim.cmd "quit"
end
end
})
This is very bad solution because it can cause neovim to crash if you accidentally quit without saving. Following errors will be repeated if you press any key in neovim:
Press ENTER or type command to continue
Error executing vim.schedule lua callback: ...e/pack/packer/start/nvim-tree.lua/lua/nvim-tree/view.lua:378: Vim(append):Error executing lua callback: /home/ywang/.config/nvim/lua/plugs/n
vimtree_config.lua:34: Vim(quit):E37: No write since last change
stack traceback:
[C]: in function 'cmd'
/home/ywang/.config/nvim/lua/plugs/nvimtree_config.lua:34: in function </home/ywang/.config/nvim/lua/plugs/nvimtree_config.lua:32>
[C]: in function 'nvim_win_close'
...e/pack/packer/start/nvim-tree.lua/lua/nvim-tree/view.lua:378: in function <...e/pack/packer/start/nvim-tree.lua/lua/nvim-tree/view.lua:356>
stack traceback:
[C]: in function 'nvim_win_close'
...e/pack/packer/start/nvim-tree.lua/lua/nvim-tree/view.lua:378: in function <...e/pack/packer/start/nvim-tree.lua/lua/nvim-tree/view.lua:356>
Press ENTER or type command to continue
I would suggest remove this tip in the README.md.
Is there any other doable solution to quit neovim when the nvim-tree is the last buffer?
Neovim version
NVIM v0.7.0
Build type: Release
LuaJIT 2.1.0-beta3
Minimal config
require'nvim-tree'.setup{
view = {
side = 'right'
},
update_focused_file = {
enable = true,
update_cwd = true,
ignore_list = {}
}
}
-- vim.cmd([[autocmd BufEnter * ++nested if winnr('$') == 1 && bufname() == 'NvimTree_' . tabpagenr() | quit | endif]])
vim.api.nvim_create_autocmd("BufEnter", {
nested = true,
callback = function()
if #vim.api.nvim_list_wins() == 1 and vim.api.nvim_buf_get_name(0):match("NvimTree_") ~= nil then
vim.cmd "quit"
end
end
})
Steps to reproduce
- open a file using nvim with nvim-tree
- edit a file
- quit without saving
- error occurs and is repeated when you press any key
Expected behavior
No response
Actual behavior
No response
josecastillolema
Metadata
Metadata
Assignees
Labels
PR pleasenvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciatednvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciateddocumentationImprovements or additions to documentationImprovements or additions to documentation
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
alex-courtis commentedon Jun 25, 2022
This is a difficult vim problem with no good solution. It's not specific to nvim-tree.
BufEnter
is the last event that can be acted upon and that event can have side effectsAny and all ideas are welcome!
There is a warning in the readme, adding this issue to the warning.
doc(#1368): more quit-on-last-window warnings
kyazdani42 commentedon Jun 25, 2022
This is unsupported feature so we won't try to hack too much around this.
alex-courtis commentedon Jun 26, 2022
See #1005 (comment)
Hxyspace commentedon Jun 26, 2022
You can add the following command to close nvim-tree before exiting neovim, this will print the error message only once on error.
kyazdani42 commentedon Jun 26, 2022
closing this, since we don't plan to help more with this undesirable feature :)
beauwilliams commentedon Jul 26, 2022
I might have the final piece for a decent working implementation, using
set confirm
we get a nice exit and prevents kicking you back into vim. It will prompt you to[Y]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel
I've also opted to parse the window layout instead of getting number of windows as this sometimes can be incorrect. I think the most reliable way to deal with these matters is parsing the window layout which is easy for this little problem :)
This solution even works for tabs (closest tab if nvimtree is last, leaving remaining tabs open)
Full snippet
I also made a branch here was considering doing a PR but depends on what other people think.
https://github.com/beauwilliams/nvim-tree.lua/tree/auto-exit-last-window
austinwilcox commentedon Jul 26, 2022
@beauwilliams That works fantastic! Just implemented it and played around with it for a little bit. I didn't run into any errors or issues.
12 remaining items