Skip to content

Commit 4117c95

Browse files
committed
fix: Hotkeys when lazy-loading
We need to either: - Rely on a global variable - Tell plugin manager on which condition to lazy-load it
1 parent 15e0247 commit 4117c95

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

README.md

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,29 @@ Install with any plugin manager or as a NeoVim package.
2424
The plugin supports lazy-loading:
2525

2626
```lua
27-
cmd = { 'IndentToggle', 'IndentEnable', 'IndentDisable' },
28-
config = function()
29-
require("indentmini").setup({
30-
only_current = false,
31-
enabled = false,
32-
char = '',
33-
minlevel = 2,
34-
key = '<F5>',
35-
exclude = { 'markdown', 'help', 'text', 'rst' },
36-
exclude_nodetype = { 'string', 'comment' }
37-
})
38-
end
27+
-- Either declare `vim.g.indentmini_key` before you load the plugin:
28+
vim.g.indentmini_key = '<F5>'
29+
30+
-- or use your plugin manager, for example Lazy.nvim:
31+
{
32+
url = 'https://github.com/nvimdev/indentmini.nvim',
33+
cmd = { 'IndentToggle', 'IndentEnable', 'IndentDisable' },
34+
keys = {
35+
{'<F5>', '<Cmd>IndentToggle<CR>', desc = 'Toggle indent guides'},
36+
},
37+
lazy = true,
38+
config = function()
39+
require("indentmini").setup({
40+
only_current = false,
41+
enabled = false,
42+
char = '',
43+
key = '<F5>', -- optional, can be set here if you don't lazy-load
44+
minlevel = 2,
45+
exclude = { 'markdown', 'help', 'text', 'rst' },
46+
exclude_nodetype = { 'string', 'comment' }
47+
})
48+
end
49+
}
3950
```
4051

4152
## Toggle functionality
@@ -50,6 +61,12 @@ You can toggle the guides via:
5061

5162
#### Hotkey
5263

64+
For lazy-loading setups, set the global variable before the plugin loads:
65+
```lua
66+
vim.g.indentmini_key = '<F5>'
67+
```
68+
69+
For non-lazy setups, use the `key` option in `setup()`:
5370
```lua
5471
require("indentmini").setup({
5572
key = '<F5>',

plugin/indentmini.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@ vim.api.nvim_create_user_command(
1515
function() require('indentmini').disable() end,
1616
{ desc = 'Disable indent guides' }
1717
)
18+
19+
if vim.g.indentmini_key then
20+
vim.keymap.set('n', vim.g.indentmini_key, '<Cmd>IndentToggle<CR>', {
21+
desc = 'Toggle indent guides',
22+
noremap = true,
23+
silent = true,
24+
})
25+
end

0 commit comments

Comments
 (0)