goolord / alpha-nvim

a lua powered greeter like vim-startify / dashboard-nvim
MIT License
1.73k stars 101 forks source link

Auto-Opening Alpha and Neotree #270

Closed EvanZhouDev closed 3 months ago

EvanZhouDev commented 3 months ago

I'm trying to have it so that when I start Neovim, Neotree is opened to the left, with Alpha opened to the right.

This is what I have so far in my Lua config:

if vim.fn.argc() == 0 then
  require'alpha'.setup(require'alpha.themes.dashboard'.config)
  vim.cmd("autocmd User AlphaReady Neotree")
else
  vim.cmd("autocmd VimEnter * Neotree")
end

However, when I do this, Alpha, which opens on the right, doesn't have its contents centered (Similar to #110). I understand (and have checked) that the fix in #110 works if I run :Neotree manually, but for some reason, doing an autocmd doesn't.

I'm quite new to Neovim, so if anyone can help me fix the Lua script to do this, it will be greatly appreciated!

EvanZhouDev commented 3 months ago

@goolord I have already used the command you suggested in my code, and it still doesn't correctly align the Alpha window... I'm still getting a visual similar to #110. I also figured out how to solve my second issue by checking argc

if vim.fn.argc() == 0 then
    require("alpha").setup(require("alpha.themes.theta").config)
    vim.cmd("autocmd User AlphaReady Neotree")
else
    vim.cmd("autocmd VimEnter * Neotree")
end

Thank you so much for the quick response, however!

EvanZhouDev commented 3 months ago

@goolord I was able to figure it out! Using vim.schedule helps it execute after Alpha finishes setting up, and Alpha detects the window resize this way.

if vim.fn.argc() == 0 then
    require("alpha").setup(require("alpha.themes.theta").config)
    local function start_up_func()
        vim.cmd("Neotree reveal")
    end
    vim.schedule(start_up_func)
else
    vim.cmd("autocmd VimEnter * Neotree")
end