Skip to content

Commit a524317

Browse files
committed
docs: reorganize Usage section and add Plugin Spec examples
- Reorder: Directory Structure before Commands - Add Plugin Spec section explaining opts/config behavior - Simplify examples (remove unnecessary init functions, opts) - Update vimdoc to match README structure
1 parent 29de5e6 commit a524317

File tree

2 files changed

+127
-131
lines changed

2 files changed

+127
-131
lines changed

README.md

Lines changed: 55 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,6 @@
77

88
A thin layer on top of Neovim's native `vim.pack`, adding support for lazy-loading and the widely adopted lazy.nvim-like declarative spec.
99

10-
```lua
11-
-- ./lua/plugins/fundo.lua
12-
return {
13-
'kevinhwang91/nvim-fundo',
14-
dependencies = { "kevinhwang91/promise-async" },
15-
cond = not vim.g.vscode,
16-
version = 'main',
17-
build = function() require('fundo').install() end,
18-
opts = {},
19-
config = function(_, opts)
20-
vim.o.undofile = true
21-
require('fundo').setup(opts)
22-
end,
23-
}
24-
```
25-
2610
**[Why zpack?](#why-zpack)** | **[Examples](#examples)** | **[Spec Reference](#spec-reference)** | **[Migrating from lazy.nvim](#migrating-from-lazynvim)**
2711

2812
## Requirements
@@ -39,57 +23,58 @@ vim.pack.add({ 'https://github.com/zuqini/zpack.nvim' })
3923
## Usage
4024

4125
```lua
42-
-- Make sure to setup `mapleader` and `maplocalleader` before
43-
-- loading zpack.nvim so that mappings are correct.
26+
-- Make sure to setup `mapleader` and `maplocalleader` before loading
27+
-- zpack.nvim so that keymaps referenced from zpack.Spec are aware
4428
vim.g.mapleader = " "
4529
vim.g.maplocalleader = "\\"
4630

4731
-- automatically import specs from `./lua/plugins/`
4832
require('zpack').setup()
4933
```
5034

51-
### Commands
52-
53-
zpack provides the following commands (default prefix: `Z`, customizable via `cmd_prefix` option):
54-
55-
- `:ZUpdate [plugin]` - Update all plugins, or a specific plugin if provided (supports tab completion). See `:h vim.pack.update()`
56-
- `:ZClean` - Remove plugins that are no longer in your spec
57-
- `:ZBuild[!] [plugin]` - Run build hook for a specific plugin, or all plugins with `!` (supports tab completion)
58-
- `:ZLoad[!] [plugin]` - Load a specific unloaded plugin, or all unloaded plugins with `!` (supports tab completion)
59-
- `:ZDelete[!] [plugin]` - Remove a specific plugin, or all plugins with `!` (supports tab completion)
60-
- Deleting active plugins in your spec can result in errors in your current session. Restart Neovim to re-install them.
61-
62-
### Directory Structure
35+
#### Directory Structure
6336

6437
Under the default setting, create plugin specs in `lua/plugins/`:
6538

6639
```
6740
lua/
6841
plugins/
6942
treesitter.lua
70-
telescope.lua
7143
lsp.lua
44+
...
7245
```
7346

7447
Each file returns a spec or list of specs (see [examples](#examples) or [spec reference](#spec-reference)):
7548

7649
```lua
77-
-- lua/plugins/telescope.lua
50+
-- ./lua/plugins/fundo.lua
7851
return {
79-
'nvim-telescope/telescope.nvim',
80-
cmd = 'Telescope',
81-
keys = {
82-
{ '<leader>ff', function() require('telescope.builtin').find_files() end, desc = 'Find files' },
83-
},
52+
'kevinhwang91/nvim-fundo',
53+
dependencies = { "kevinhwang91/promise-async" },
54+
cond = not vim.g.vscode,
55+
version = 'main',
56+
build = function() require('fundo').install() end,
8457
opts = {},
85-
-- config is executed when the plugin loads. The default implementation will automatically run require(MAIN).setup(opts) if opts or config = true is set.
86-
config = function()
87-
...
58+
config = function(_, opts)
59+
vim.o.undofile = true
60+
require('fundo').setup(opts)
8861
end,
8962
}
9063
```
9164

92-
### Configurations
65+
#### Commands
66+
67+
zpack provides the following commands (default prefix: `Z`, customizable via `cmd_prefix` option):
68+
69+
- `:ZUpdate [plugin]` - Update all plugins, or a specific plugin if provided (supports tab completion). See `:h vim.pack.update()`
70+
- `:ZClean` - Remove plugins that are no longer in your spec
71+
- `:ZBuild[!] [plugin]` - Run build hook for a specific plugin, or all plugins with `!` (supports tab completion)
72+
- `:ZLoad[!] [plugin]` - Load a specific unloaded plugin, or all unloaded plugins with `!` (supports tab completion)
73+
- `:ZDelete[!] [plugin]` - Remove a specific plugin, or all plugins with `!` (supports tab completion)
74+
- Deleting active plugins in your spec can result in errors in your current session. Restart Neovim to re-install them.
75+
76+
77+
#### Configurations
9378

9479
```lua
9580
require('zpack').setup({
@@ -107,7 +92,7 @@ require('zpack').setup({
10792

10893
Plugin-level settings always take precedence over `defaults`.
10994

110-
### Importing Specs
95+
#### Importing Specs
11196

11297
```lua
11398
-- automatically import specs from `./lua/plugins/`
@@ -167,6 +152,30 @@ For more examples, refer to example config:
167152
- [zpack installation and setup](https://github.com/zuqini/nvim/blob/main/init.lua)
168153
- [plugins directory structure](https://github.com/zuqini/nvim/tree/main/lua/plugins)
169154

155+
#### Plugin Spec
156+
157+
```lua
158+
return {
159+
'nvim-mini/mini.bracketed',
160+
-- If `opts` or `config = true` is set,
161+
-- the config hook calls `require(MAIN).setup(opts)` by default.
162+
opts = {}, -- calls `require('mini.bracketed').setup({})`
163+
}
164+
```
165+
166+
```lua
167+
return {
168+
'nvim-lualine/lualine.nvim',
169+
opts = { theme = 'tokyonight' },
170+
-- Explicitly define a `config` function hook if you need to run custom logic on plugin load.
171+
-- The resolved `zpack.Plugin` and `opts` table are passed as its arguments:
172+
config = function(_, opts)
173+
vim.opt.showmode = false
174+
require('lualine').setup(opts)
175+
end,
176+
}
177+
```
178+
170179
#### Lazy Load on Command
171180

172181
```lua
@@ -196,18 +205,17 @@ return {
196205
return {
197206
'windwp/nvim-autopairs',
198207
event = 'InsertEnter', -- Also supports 'VeryLazy'
199-
opts = { check_ts = true },
208+
opts = {},
200209
}
201210
```
202211

203212
#### Lazy Load on Event with Pattern
204213

205214
```lua
206-
-- Inline pattern (same as lazy.nvim)
215+
-- Inline pattern
207216
return {
208217
'rust-lang/rust.vim',
209218
event = 'BufReadPre *.rs',
210-
init = function() vim.g.rustfmt_autosave = 1 end,
211219
}
212220

213221
-- Or using EventSpec for multiple patterns
@@ -229,7 +237,6 @@ Load plugin when opening files of specific types. Automatically re-triggers `Buf
229237
return {
230238
'rust-lang/rust.vim',
231239
ft = { 'rust', 'toml' },
232-
init = function() vim.g.rustfmt_autosave = 1 end,
233240
}
234241
```
235242

@@ -302,29 +309,14 @@ return {
302309
Control plugin load order with priority (higher values load first; default: 50):
303310

304311
```lua
305-
-- Startup plugin: load colorscheme early
312+
-- to load colorscheme early
306313
return {
307314
'folke/tokyonight.nvim',
308315
priority = 1000,
309316
config = function() vim.cmd('colorscheme tokyonight') end,
310317
}
311318
```
312319

313-
#### Custom Config Function
314-
315-
When you need custom configuration logic, use a `config` function. The resolved `opts` table is passed as the second argument:
316-
317-
```lua
318-
return {
319-
'nvim-lualine/lualine.nvim',
320-
opts = { theme = 'tokyonight' },
321-
config = function(_, opts)
322-
opts.sections = { lualine_a = { 'mode' } }
323-
require('lualine').setup(opts)
324-
end,
325-
}
326-
```
327-
328320
#### Using Plugin Data in Hooks
329321

330322
All lifecycle hooks (`init`, `config`, `build`, `cond`) and lazy-loading triggers (`event`, `cmd`, `keys`, `ft`) can be functions that receive a `zpack.Plugin` object containing the resolved plugin path and spec:
@@ -348,7 +340,7 @@ If automatic module detection fails, specify the module explicitly with `main`:
348340
return {
349341
'some/plugin-with-unusual-structure',
350342
main = 'plugin.core',
351-
opts = { enabled = true },
343+
opts = {},
352344
}
353345
```
354346

0 commit comments

Comments
 (0)