Avimitin / nvim

Useful, maintainable, multi-language supported neovim configuration.
https://avimitin.github.io/nvim
Apache License 2.0
273 stars 48 forks source link

Statusline checkwidth ivent on window(split) resize #43

Closed ttytm closed 2 years ago

ttytm commented 2 years ago

I tried my best, but unfortunately I couldn't figure out how to update the statusline-width-depended-conditional-state on window split resize events.

There is unfortunately no default vim event for this, and I failed to create a custom event.

For the condition to apply, it takes the default vim events like moving in and out of a split, or when doing an application window resize.

You are for sure a much better developer then me, so I thought I'll open an issue on it, and maybe you have a quick solution to have a more dynamic behavior of the status line.

Avimitin commented 2 years ago

Are you writing your own statusline or just modifying the galaxy line plugin?

Avimitin commented 2 years ago

And you can use the WinNew autocmd to do what you want:

                            *WinNew*
WinNew              When a new window was created.  Not done for
                the first window, when Vim has just started.
                Before WinEnter.
ttytm commented 2 years ago

Hey hello, thanks for your reply 🙂

When I found your config a while ago, I used it as a base, I really like it 😊 so yeah, we could say modifying it so the checkwidth condition it behaves a little more dynamic.

Thanks for the suggestion, unfortunately, there is no vim event that tracks split resize actions. But I had luck finding a solution by piping the load function onto my resize shortcuts. I don't know if his is good in terms of resource usage, but it does the job and a custom event with an autocmd probably wouldn't do anything different.

E.g.,:

vim.keymap.set("n", "<C-Left>", ":vertical resize -2 | lua require('galaxyline').load_galaxyline()<Cr>", { desc = "Decrease window width" })
vim.keymap.set("n", "<C-Right>", ":vertical resize +2 | lua require('galaxyline').load_galaxyline()<Cr>", { desc = "Increase window width" })

Thanks again for getting back

Avimitin commented 2 years ago

Have you tried this autocmd?

VimResized          After the Vim window was resized, thus 'lines'
                and/or 'columns' changed.  Not when starting
                up though.

Update, this is not working, this affects only when the whole window are resized.

Avimitin commented 2 years ago

Done, I found the auto command that can do this stuff:

                            *WinScrolled*
WinScrolled         After scrolling the content of a window or
                resizing a window.
                The pattern is matched against the
                |window-ID|.  Both <amatch> and <afile> are
                set to the |window-ID|.
                Non-recursive (the event cannot trigger
                itself).  However, if the command causes the
                window to scroll or change size another
                WinScrolled event will be triggered later.
                Does not trigger when the command is added,
                only after the first scroll or resize.
Avimitin commented 2 years ago

So if you are using Lua configuration and neovim 0.7.0+, you can add the below lines into your configuration:

vim.api.nvim_create_autocmd("WinScrolled", {
  callback = function()
    require('galaxyline').load_galaxyline()
  end,
})

If you are using Lua configuration but neovim 0.6.0, you can add the below lines:

vim.cmd("au WinScrolled * lua require("galaxyline").load_galaxyline()")
ttytm commented 2 years ago

Nice, thanks I need to check this one out, I'm worrying that this one will unstoppably reload galaxyline also when using <c-d> <c-u> and similar. But I'm probably misinterpreting the event.

In any case, this could probably be made even better when performing another check width inside the function and only loading galaxyline when a defined window size is reached.

Avimitin commented 2 years ago

It will invoke the reload when you scroll the window. I am confused about this too. They named it WinScrolled but embed two functionality inside one auto commands. Maybe we should open a issue at Neovim repository.

ttytm commented 2 years ago

I think so too, there should be events that can target one of these behaviors exclusively.