Repository navigation
Lazy loading plugins you don't need in terminal mode #2176
Replies: 1 comment 1 reply
|
The custom event approach is a reasonable way to defer terminal-irrelevant plugins, and the startup improvement is measurable. I would keep the event, but document the lifecycle and the exceptions clearly. The main edge cases are:
For plugins that should load only when a real file buffer exists, a standard BufReadPre, BufNewFile, or FileType event may be easier for readers to understand than a custom event. The custom event is still useful when you want one controlled transition from terminal mode to editing mode. Avoid using a condition that prevents the plugin from ever loading after the first tab. I would keep the startup benchmark with nvim --startuptime and also measure the first file open, not only nvim -c q. That verifies the saved 50 ms did not simply move the cost into the first editing action. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
If like me you use Nvim as your main terminal emulator (I run fish inside Nvim inside fish inside Kitty, as explained here neovim/neovim#40972 and it includes at the end a guide to do something similar), and you have 100 plugins (it's not overkill, 80% of them are just for basic features that Nvim doesn't natively implement) you have noticed something: it is slow to open a new tab. Because kitty + fish + nvim + fish (again) are involved every time you open a tab. If you CPU is already busy it can take entire seconds.
But we didn't leave IDE world to waste seconds waiting on nvim to open. We are here to waste days implementing solutions that save us seconds.
I was always frustrated tha lazy.nvim didn't let me lazy load a plugin in a way that my plugins are not loaded in terminal mode (the one I start with) and load them once I left the terminal to open a real file.
I finally made it, for some reasons custom lazy Events are not documented, but they are extremely easy to make (probably 100 times easier than making a telescope finder if you ever done it, what a terrible API they have). RIght there https://github.com/ilan-schemoul/nvim-config/blob/f2014aef160dbef564b3828c743e2b722dde72d2/nvim/lua/config/lazy.lua#L17.
Result is going from 120ms to 70ms (as reported by time nvim -c ':q' not by Lazy). And Lazy reports less than 50ms to get to UIEnter (for 101 plugins it's really good).
All reactions