dashboard-nvim icon indicating copy to clipboard operation
dashboard-nvim copied to clipboard

Open Dashboard when last window is closed

Open 1995parham opened this issue 2 years ago • 3 comments

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.

1995parham avatar Jul 28 '23 08:07 1995parham

any updates on this?

tidaeu avatar Oct 07 '23 04:10 tidaeu

take a look at later.

glepnir avatar Oct 07 '23 05:10 glepnir

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

KaspervdHeijden avatar Mar 03 '24 19:03 KaspervdHeijden