Write autoclose command in lua #1115
-
I saw the change made to the auto-close feature and I'm trying to maintain this functionality but how can I write the following in lua ? autocmd BufEnter * ++nested if winnr('$') == 1 && bufname() == 'NvimTree_' . tabpagenr() | quit | endif Thanks @alex-courtis: this can catastrophically fail #1368. Use with great caution. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
with 0.7: 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
}) |
Beta Was this translation helpful? Give feedback.
-
Btw, is it a way to fix autoclose command to cover a following case:
I tried something like that (where au(
"BufDelete",
"NvimTree*",
function()
▏ g.nvimtree_was_unloaded = true
end
)
au(
"BufWinEnter",
'*',
function()
▏ if g.nvimtree_was_unloaded and vim.api.nvim_buf_get_name(0) == "" then
▏ ▏ print(#vim.api.nvim_list_wins()) -- it shows there stays 2 more windows!!!
▏ ▏ vim.cmd[[silent! quitall!]] -- it works most of the time, but leads to unexpected behaviour in some situations
▏ end
end
)
au2("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 "silent! quitall!"
▏ end
end
}) but as I commented in code block, it is not ideal soluton, and sometimes makes vim to exit, when it is not intended to. |
Beta Was this translation helpful? Give feedback.
-
I gave up trying BufEnter kind of setup, was not able to make it work with telescope, so want to share this dummy solution I came up with for me.
|
Beta Was this translation helpful? Give feedback.
with 0.7: