nvimdev / dashboard-nvim

vim dashboard
MIT License
2.21k stars 179 forks source link

Open Dashboard when last window is closed #372

Open 1995parham opened 11 months ago

1995parham commented 11 months ago

I want to have a way to open dashboard again when I closed my last window/buffer. I cannot find a way for it, so if there is a way for doing it, it would be great if we can have it in project readme/wiki.

tidaeu commented 9 months ago

any updates on this?

glepnir commented 9 months ago

take a look at later.

KaspervdHeijden commented 4 months ago

I have added this in my ./lua/plugins/dashboard.lua which seems to do the trick:

-- somewhere in my config function ...

vim.defer_fn(
    function ()
        vim.api.nvim_create_autocmd(
            'BufDelete',
            {
                group    = vim.api.nvim_create_augroup('open-dashboard-after-last-buffer-close', { clear = true }),
                callback = function (event)
                    for buf = 1, vim.fn.bufnr('$') do
                        if buf ~= event.buf and vim.fn.buflisted(buf) == 1 then
                            if vim.api.nvim_buf_get_name(buf) ~= '' and vim.bo[buf].filetype ~= 'dashboard' then
                                return
                            end                                                                                     
                        end
                    end

                    vim.cmd('Dashboard')
                end,
            }
        )
    end,
    0
)

Edit: put in vim.defer_fn() to fix an issue with lualine not showing