How to avoid empty buffer from opening #92
-
Hello, I am new to this plugin, and noticed that every time a session loads it also gets loaded an extra empty buffer which was not there before. Is it any way of getting rid of it? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
That's odd and definitely not default behaviour. Suggest raising an issue and following the steps outlined in there |
Beta Was this translation helpful? Give feedback.
-
Spent like 5 hours trying to recreate the issue with minimal.lua, I disabled and renabled the plugin again with my init.lua and now it works. Guess we'll never know what happend |
Beta Was this translation helpful? Give feedback.
-
I think I was seeing this same behavior but was addressed by setting |
Beta Was this translation helpful? Give feedback.
-
I spent some time trying to dig into what's happening and I think it's some combination of netrw and/or starting neovim with arguments. Without yet uncovering the root cause, I have a solution with an autocmd/hook to delete all buffers for directories: local persisted_hook_group = vim.api.nvim_create_augroup("PersistedHooks", {})
vim.api.nvim_create_autocmd({ "User" }, {
pattern = "PersistedStateChange",
group = persisted_hook_group,
callback = function()
local function dir_buffer_filter(buf)
if not vim.api.nvim_buf_is_valid(buf) or not vim.api.nvim_buf_get_option(buf, 'buflisted') then
return false
end
local filetype = vim.api.nvim_buf_get_option(buf, 'filetype')
if filetype == 'netrw' then return true end
local buftype = vim.api.nvim_buf_get_option(buf, 'buftype')
if buftype == 'nofile' or buftype == 'prompt' then return true end
local name = vim.api.nvim_buf_get_name(buf)
local path = vim.loop.fs_realpath(vim.fn.expand(name))
if path == nil then
return false
end
return vim.fn.isdirectory(path) ~= 0
end
local buffers_to_del = vim.tbl_filter(dir_buffer_filter, vim.api.nvim_list_bufs())
for _, buffer in ipairs(buffers_to_del) do
vim.api.nvim_buf_delete(buffer, {})
end
end,
}) |
Beta Was this translation helpful? Give feedback.
That's odd and definitely not default behaviour. Suggest raising an issue and following the steps outlined in there