:sloth: A lazy-loading module for rocks.nvim
48
stars
21
commits
Lua
primary language
Sep 5, 2026
updated
rocks-lazy.nvim is a rocks.nvim module that helps you lazy-load
your rocks.nvim plugins using
the lz.n library.
[!NOTE]
Should I lazy-load plugins?
It should be a plugin author's responsibility to ensure their plugin doesn't unnecessarily impact startup time, not yours!
See our "DO's and DONT's" guide for plugin developers.
Regardless, the current status quo is horrible, and some authors may not have the will or capacity to improve their plugins' startup impact.
If you find a plugin that takes too long to load, or worse, forces you to load it manually at startup with a call to a heavy
setupfunction, consider opening an issue on the plugin's issue tracker.
[!IMPORTANT]
With luarocks, libraries do not have a meaningful impact on startup time and don't need to be lazy-loaded.
This plugin handles lazy-loading of plugin initialization scripts.
rocks.nvim.Simply run :Rocks install rocks-lazy.nvim,
and you are good to go!
rocks.tomlWith this module installed, you can add the fields that tell rocks-lazy.nvim
how to lazy-load to a [plugins] entry in your rocks.toml.
eventLazy-load on an event (:h autocmd-events).
string? or string[]Events can be specified with or without patterns, e.g.
BufEnter or BufEnter *.lua.
Example:
[plugins.nvim-cmp]
version = "scm"
event = "InsertEnter"
[plugins]
nvim-cmp = { version = "scm", event = "InsertEnter" }
cmdLazy-load on a command (:h user-commands).
string? or string[]Example:
[plugins."telescope.nvim"]
version = "0.1.8"
cmd = "Telescope"
[plugins]
"telescope.nvim" = { version = "0.1.8", cmd = "Telescope" }
ftLazy-load on a :h filetype event.
string? or string[]Example:
[plugins.neorg]
version = "8.0.0"
ft = "norg"
[plugins]
neorg = { version = "8.0.0", ft = "norg" }
keysLazy-load on key mappings.
string? or string[] or rocks.lazy.KeysSpec[]Where rocks.lazy.KeysSpec is a table with the following fields:
lhs: stringrhs: string?mode: string? or string[] (default: "n")[string]: Options, see :h vim.keymap.set[!NOTE]
- If unspecified, the default
modeisn.- The
lhsandrhsfields differ from thelz.n.PluginSpec1.
Examples:
[plugins."neo-tree.nvim"]
version = "scm"
keys = { lhs = "<leader>ft", rhs = "<CMD>Neotree toggle<CR>", desc = "NeoTree toggle" }
[plugins."dial.nvim"]
version = "0.4.0"
keys = ["<C-a>", { lhs = "<C-x>", mode = "n" }]
[plugins]
"neo-tree.nvim" = { version = "scm", keys = { "<leader>ft", "<CMD>Neotree toggle<CR>", desc = "NeoTree toggle" } }
colorschemeLazy-load when setting a colorscheme.
string? or string[]Example:
[plugins."kanagawa.nvim"]
version = "1.0.0"
colorscheme = [
"kanagawa",
"kanagawa-dragon",
"kanagawa-lotus",
"kanagawa-wave"
]
[plugins]
"sweetie.nvim" = { version = "1.0.0", colorscheme = "sweetie" }
[!TIP]
You can specify combinations of the above lazy-loading fields
Example:
[plugins."telescope.nvim"] version = "0.1.8" cmd = "Telescope" keys = [ { lhs = "<leader>t", rhs = "<CMD>Telescope<CR>" } ]Whichever event occurs first will load the plugin.
If you prefer using Lua for configuration,
you can add a import option to your rocks.toml:
[!IMPORTANT]
- If you use Lua to configure lazy-loading, you must set
opt = truein your rocks.toml entries.- Lua specs do not automatically integrate with rocks-config.nvim. You can do so manually in the
beforehook.
[rocks_lazy]
import = "lazy_specs/"
This is a subdirectory (relative to nvim/lua)
to search for plugin specs.
In this example, you can add a lua/lazy_specs/ directory
to your nvim config, with a lua script for each plugin.
── nvim
├── lua
│ └── lazy_specs # Your plugin specs go here.
│ └── init.lua # Optional top-level module returning a list of specs
│ └── neorg.lua # Single spec
│ └── sweetie.lua
├── init.lua
Or
── nvim
├── lua
│ └── lazy_specs.lua # Optional top-level module returning a list of specs
├── init.lua
lz.n documentation.lz.n.PluginSpec.[!IMPORTANT]
If you use a module to import your plugin specs and you also use
rocks-config.nvim, therocks-lazyimportmodule name must not clash with therocks-configplugins_dir.
[!TIP]
You can use both
rocks.tomlentries and a Lua config to configure your plugin specs.rocks-lazy.nvimwill extend2 the rocks.toml specs with the imported ones.
rocks-config interoperabilityIf you are using rocks-config.nvim >= 2.0.0,
it will not load configs for any opt plugins.
rocks-lazy will use the rocks-config API to load them in the
lz.n.PluginSpec.before hooks.
[!TIP]
If you use Lua to configure lazy-loading, you can invoke the default
beforehook by callingrequire("rocks-lazy").default_before_hook(plugin).
rocks-lazy.nvim is licensed under GPLv3.
21 commits
Lua
50.9%
Nix
48.9%
:sloth: A lazy-loading module for rocks.nvim
48
stars
21
commits
Lua
primary language
Sep 5, 2026
updated
rocks-lazy.nvim is a rocks.nvim module that helps you lazy-load
your rocks.nvim plugins using
the lz.n library.
[!NOTE]
Should I lazy-load plugins?
It should be a plugin author's responsibility to ensure their plugin doesn't unnecessarily impact startup time, not yours!
See our "DO's and DONT's" guide for plugin developers.
Regardless, the current status quo is horrible, and some authors may not have the will or capacity to improve their plugins' startup impact.
If you find a plugin that takes too long to load, or worse, forces you to load it manually at startup with a call to a heavy
setupfunction, consider opening an issue on the plugin's issue tracker.
[!IMPORTANT]
With luarocks, libraries do not have a meaningful impact on startup time and don't need to be lazy-loaded.
This plugin handles lazy-loading of plugin initialization scripts.
rocks.nvim.Simply run :Rocks install rocks-lazy.nvim,
and you are good to go!
rocks.tomlWith this module installed, you can add the fields that tell rocks-lazy.nvim
how to lazy-load to a [plugins] entry in your rocks.toml.
eventLazy-load on an event (:h autocmd-events).
string? or string[]Events can be specified with or without patterns, e.g.
BufEnter or BufEnter *.lua.
Example:
[plugins.nvim-cmp]
version = "scm"
event = "InsertEnter"
[plugins]
nvim-cmp = { version = "scm", event = "InsertEnter" }
cmdLazy-load on a command (:h user-commands).
string? or string[]Example:
[plugins."telescope.nvim"]
version = "0.1.8"
cmd = "Telescope"
[plugins]
"telescope.nvim" = { version = "0.1.8", cmd = "Telescope" }
ftLazy-load on a :h filetype event.
string? or string[]Example:
[plugins.neorg]
version = "8.0.0"
ft = "norg"
[plugins]
neorg = { version = "8.0.0", ft = "norg" }
keysLazy-load on key mappings.
string? or string[] or rocks.lazy.KeysSpec[]Where rocks.lazy.KeysSpec is a table with the following fields:
lhs: stringrhs: string?mode: string? or string[] (default: "n")[string]: Options, see :h vim.keymap.set[!NOTE]
- If unspecified, the default
modeisn.- The
lhsandrhsfields differ from thelz.n.PluginSpec1.
Examples:
[plugins."neo-tree.nvim"]
version = "scm"
keys = { lhs = "<leader>ft", rhs = "<CMD>Neotree toggle<CR>", desc = "NeoTree toggle" }
[plugins."dial.nvim"]
version = "0.4.0"
keys = ["<C-a>", { lhs = "<C-x>", mode = "n" }]
[plugins]
"neo-tree.nvim" = { version = "scm", keys = { "<leader>ft", "<CMD>Neotree toggle<CR>", desc = "NeoTree toggle" } }
colorschemeLazy-load when setting a colorscheme.
string? or string[]Example:
[plugins."kanagawa.nvim"]
version = "1.0.0"
colorscheme = [
"kanagawa",
"kanagawa-dragon",
"kanagawa-lotus",
"kanagawa-wave"
]
[plugins]
"sweetie.nvim" = { version = "1.0.0", colorscheme = "sweetie" }
[!TIP]
You can specify combinations of the above lazy-loading fields
Example:
[plugins."telescope.nvim"] version = "0.1.8" cmd = "Telescope" keys = [ { lhs = "<leader>t", rhs = "<CMD>Telescope<CR>" } ]Whichever event occurs first will load the plugin.
If you prefer using Lua for configuration,
you can add a import option to your rocks.toml:
[!IMPORTANT]
- If you use Lua to configure lazy-loading, you must set
opt = truein your rocks.toml entries.- Lua specs do not automatically integrate with rocks-config.nvim. You can do so manually in the
beforehook.
[rocks_lazy]
import = "lazy_specs/"
This is a subdirectory (relative to nvim/lua)
to search for plugin specs.
In this example, you can add a lua/lazy_specs/ directory
to your nvim config, with a lua script for each plugin.
── nvim
├── lua
│ └── lazy_specs # Your plugin specs go here.
│ └── init.lua # Optional top-level module returning a list of specs
│ └── neorg.lua # Single spec
│ └── sweetie.lua
├── init.lua
Or
── nvim
├── lua
│ └── lazy_specs.lua # Optional top-level module returning a list of specs
├── init.lua
lz.n documentation.lz.n.PluginSpec.[!IMPORTANT]
If you use a module to import your plugin specs and you also use
rocks-config.nvim, therocks-lazyimportmodule name must not clash with therocks-configplugins_dir.
[!TIP]
You can use both
rocks.tomlentries and a Lua config to configure your plugin specs.rocks-lazy.nvimwill extend2 the rocks.toml specs with the imported ones.
rocks-config interoperabilityIf you are using rocks-config.nvim >= 2.0.0,
it will not load configs for any opt plugins.
rocks-lazy will use the rocks-config API to load them in the
lz.n.PluginSpec.before hooks.
[!TIP]
If you use Lua to configure lazy-loading, you can invoke the default
beforehook by callingrequire("rocks-lazy").default_before_hook(plugin).
rocks-lazy.nvim is licensed under GPLv3.
21 commits
Lua
50.9%
Nix
48.9%