@icarusmx/creta 1.5.18 → 1.5.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
# Exercise 16: Customizing Fold Keymaps in Neovim (zN instead of zR)
|
|
2
|
+
|
|
3
|
+
**Objective:** Replace the default `zR` (unfold all) mapping with `zN` so you can unfold all folds with a more intuitive keymap that aligns with your nvim muscle memory.
|
|
4
|
+
|
|
5
|
+
**Time to complete:** 15 minutes
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Why This Matters
|
|
10
|
+
|
|
11
|
+
Neovim's default fold keymaps follow traditional Vi conventions:
|
|
12
|
+
- `zR` = unfold all (Reduce folds)
|
|
13
|
+
- `zM` = fold all (More folds)
|
|
14
|
+
|
|
15
|
+
The letter choices are cryptic. If you prefer mnemonics like:
|
|
16
|
+
- `zN` = unfold all (N for "opeN")
|
|
17
|
+
- `zM` = fold all (M stays the same - "More folds" works)
|
|
18
|
+
|
|
19
|
+
...then this exercise shows you how to map them in your `init.lua`.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Step 1: Understand the Default Fold Keymaps
|
|
24
|
+
|
|
25
|
+
First, let's see what fold mappings exist by default.
|
|
26
|
+
|
|
27
|
+
Open your Neovim and check the current mappings:
|
|
28
|
+
|
|
29
|
+
```vim
|
|
30
|
+
:help fold-commands
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The key ones are:
|
|
34
|
+
| Mapping | Action | Default |
|
|
35
|
+
|---------|--------|---------|
|
|
36
|
+
| `zR` | Unfold all | Open all folds in buffer |
|
|
37
|
+
| `zM` | Fold all | Close all folds in buffer |
|
|
38
|
+
| `zr` | Unfold one level | Open one level of folds |
|
|
39
|
+
| `zm` | Fold one level | Close one level of folds |
|
|
40
|
+
| `za` | Toggle fold | Toggle fold at cursor |
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Step 2: Locate Your init.lua
|
|
45
|
+
|
|
46
|
+
Your Neovim configuration file is typically at one of these locations:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# Check which one exists
|
|
50
|
+
ls ~/.config/nvim/init.lua
|
|
51
|
+
ls ~/AppData/Local/nvim/init.lua # Windows
|
|
52
|
+
ls ~/.config/nvim/init.vim # Old init.vim (less common now)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The standard location on macOS/Linux:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
~/.config/nvim/init.lua
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Step 3: Add the Custom Keymap
|
|
64
|
+
|
|
65
|
+
Open your `init.lua` in Neovim:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
nvim ~/.config/nvim/init.lua
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Add these lines to create the `zN` mapping:
|
|
72
|
+
|
|
73
|
+
```lua
|
|
74
|
+
-- Fold keymaps customization
|
|
75
|
+
-- Use zN to unfold all (instead of zR)
|
|
76
|
+
vim.keymap.set('n', 'zN', 'zR', { noremap = true, silent = true, desc = 'Unfold all' })
|
|
77
|
+
|
|
78
|
+
-- Optional: keep zR as a backup
|
|
79
|
+
-- (Remove this line if you want to completely replace zR with zN)
|
|
80
|
+
-- vim.keymap.set('n', 'zR', 'zN', { noremap = true, silent = true, desc = 'Unfold all (backup)' })
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**What each part does:**
|
|
84
|
+
- `'n'` - Normal mode only
|
|
85
|
+
- `'zN'` - The new key you want to press
|
|
86
|
+
- `'zR'` - The command it executes (the built-in unfold all)
|
|
87
|
+
- `noremap = true` - Don't remap recursively
|
|
88
|
+
- `silent = true` - Don't show the command in status line
|
|
89
|
+
- `desc` - Help text when you do `:map zN`
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Step 4: Remove or Remap zR
|
|
94
|
+
|
|
95
|
+
If you want `zR` to stop working (force yourself to use `zN`), add this:
|
|
96
|
+
|
|
97
|
+
```lua
|
|
98
|
+
-- Disable zR so only zN works
|
|
99
|
+
vim.keymap.set('n', 'zR', '<nop>', { noremap = true, silent = true, desc = 'Disabled - use zN instead' })
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Or remap `zR` to something else:
|
|
103
|
+
|
|
104
|
+
```lua
|
|
105
|
+
-- Remap zR to unfold one level (what zr does)
|
|
106
|
+
vim.keymap.set('n', 'zR', 'zr', { noremap = true, silent = true, desc = 'Unfold one level' })
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Step 5: Save and Reload
|
|
112
|
+
|
|
113
|
+
In Neovim:
|
|
114
|
+
|
|
115
|
+
```vim
|
|
116
|
+
:w " Save the file
|
|
117
|
+
:source % " Reload the configuration
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Or exit and restart Neovim:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
exit
|
|
124
|
+
nvim
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Step 6: Test Your New Mapping
|
|
130
|
+
|
|
131
|
+
1. Open any file with folds (or create one with folds using `:set foldmethod=syntax`)
|
|
132
|
+
2. Press `zM` to fold all
|
|
133
|
+
3. Press `zN` to unfold all
|
|
134
|
+
4. Verify it works!
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Complete Configuration Example
|
|
139
|
+
|
|
140
|
+
Here's what your `~/.config/nvim/init.lua` fold section should look like:
|
|
141
|
+
|
|
142
|
+
```lua
|
|
143
|
+
-- ============================================================================
|
|
144
|
+
-- FOLD KEYMAPS
|
|
145
|
+
-- ============================================================================
|
|
146
|
+
|
|
147
|
+
-- Custom fold mappings for better muscle memory
|
|
148
|
+
vim.keymap.set('n', 'zN', 'zR', { noremap = true, silent = true, desc = 'Unfold all (zN)' })
|
|
149
|
+
vim.keymap.set('n', 'zM', 'zM', { noremap = true, silent = true, desc = 'Fold all (zM)' })
|
|
150
|
+
|
|
151
|
+
-- Optional: Disable zR to force zN usage
|
|
152
|
+
-- vim.keymap.set('n', 'zR', '<nop>', { noremap = true, silent = true })
|
|
153
|
+
|
|
154
|
+
-- Optional: Map for one-level fold/unfold with intuitive keys
|
|
155
|
+
-- vim.keymap.set('n', 'zn', 'zr', { noremap = true, silent = true, desc = 'Unfold one level' })
|
|
156
|
+
-- vim.keymap.set('n', 'zm', 'zm', { noremap = true, silent = true, desc = 'Fold one level' })
|
|
157
|
+
|
|
158
|
+
-- ============================================================================
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## Verification: Check Your Mapping
|
|
164
|
+
|
|
165
|
+
After reloading, verify the mapping exists:
|
|
166
|
+
|
|
167
|
+
```vim
|
|
168
|
+
:map zN
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
You should see:
|
|
172
|
+
```
|
|
173
|
+
n zN zR
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
This confirms `zN` now executes `zR` (unfold all).
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## Advanced: Create a Fold Mode Function
|
|
181
|
+
|
|
182
|
+
If you want even more control, create a function:
|
|
183
|
+
|
|
184
|
+
```lua
|
|
185
|
+
-- Function-based fold toggle
|
|
186
|
+
local function toggle_fold_level()
|
|
187
|
+
-- Get current fold level
|
|
188
|
+
local fold_level = vim.fn.foldlevel(vim.fn.line('.'))
|
|
189
|
+
|
|
190
|
+
if fold_level > 0 then
|
|
191
|
+
vim.cmd('zN') -- Unfold all
|
|
192
|
+
else
|
|
193
|
+
vim.cmd('zM') -- Fold all
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
vim.keymap.set('n', 'z<Space>', toggle_fold_level, { noremap = true, silent = true, desc = 'Toggle fold state' })
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Then pressing `z<Space>` intelligently toggles between fold all and unfold all.
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## Troubleshooting
|
|
205
|
+
|
|
206
|
+
### Mapping doesn't work
|
|
207
|
+
**Problem:** You press `zN` and nothing happens.
|
|
208
|
+
|
|
209
|
+
**Solution:**
|
|
210
|
+
1. Verify the mapping was loaded: `:map zN`
|
|
211
|
+
2. Check for conflicts: `:verbose map zN`
|
|
212
|
+
3. Make sure you're in Normal mode (press `Esc` first)
|
|
213
|
+
4. Reload config: `:source %`
|
|
214
|
+
|
|
215
|
+
### Old mapping still works
|
|
216
|
+
**Problem:** `zR` still unfolds even though you wanted to disable it.
|
|
217
|
+
|
|
218
|
+
**Solution:**
|
|
219
|
+
- Make sure you added the `<nop>` mapping for `zR`
|
|
220
|
+
- Restart Neovim completely (`:q!` then `nvim`)
|
|
221
|
+
- Check if another plugin is defining `zR`: `:verbose map zR`
|
|
222
|
+
|
|
223
|
+
### Fold commands not working
|
|
224
|
+
**Problem:** `zN` executes but nothing happens.
|
|
225
|
+
|
|
226
|
+
**Solution:**
|
|
227
|
+
- Make sure the buffer has folds: `:set foldmethod=syntax` or `:set foldmethod=manual`
|
|
228
|
+
- The buffer must have fold markers (depends on `foldmethod`)
|
|
229
|
+
- Check the file type supports folding
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## Related Keymaps Worth Adding
|
|
234
|
+
|
|
235
|
+
While you're customizing folds, consider these related mappings:
|
|
236
|
+
|
|
237
|
+
```lua
|
|
238
|
+
-- Complete fold mapping suite
|
|
239
|
+
vim.keymap.set('n', 'zN', 'zR', { noremap = true, silent = true, desc = 'Unfold all' })
|
|
240
|
+
vim.keymap.set('n', 'zM', 'zM', { noremap = true, silent = true, desc = 'Fold all' })
|
|
241
|
+
vim.keymap.set('n', 'zn', 'zr', { noremap = true, silent = true, desc = 'Unfold one level' })
|
|
242
|
+
vim.keymap.set('n', 'zm', 'zm', { noremap = true, silent = true, desc = 'Fold one level' })
|
|
243
|
+
vim.keymap.set('n', 'zc', 'zc', { noremap = true, silent = true, desc = 'Close fold' })
|
|
244
|
+
vim.keymap.set('n', 'zo', 'zo', { noremap = true, silent = true, desc = 'Open fold' })
|
|
245
|
+
vim.keymap.set('n', 'za', 'za', { noremap = true, silent = true, desc = 'Toggle fold' })
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## Pro Tips
|
|
251
|
+
|
|
252
|
+
1. **Use modelines** - Add to the top of files you edit frequently:
|
|
253
|
+
```vim
|
|
254
|
+
" vim: set foldmethod=syntax foldlevel=1 :
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
2. **Set default foldlevel** - Add to `init.lua`:
|
|
258
|
+
```lua
|
|
259
|
+
vim.opt.foldlevel = 1 -- Start with one level of folds open
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
3. **Use with LazyVim** - If using LazyVim, add to `~/.config/nvim/lua/config/keymaps.lua`:
|
|
263
|
+
```lua
|
|
264
|
+
-- Already might have keymaps there
|
|
265
|
+
vim.keymap.set('n', 'zN', 'zR', { desc = 'Unfold all' })
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
4. **Vim muscle memory** - Remember: `z` is for "**z**ones" (folds), then:
|
|
269
|
+
- `N` = ope**N** all
|
|
270
|
+
- `M` = **M**ore closed
|
|
271
|
+
- `C` = **C**lose
|
|
272
|
+
- `O` = **O**pen
|
|
273
|
+
- `A` = **A**lternate (toggle)
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
## Summary
|
|
278
|
+
|
|
279
|
+
You've successfully:
|
|
280
|
+
- ✅ Understood Neovim's default fold keymaps
|
|
281
|
+
- ✅ Located your `init.lua` configuration
|
|
282
|
+
- ✅ Created a custom `zN` mapping for unfold all
|
|
283
|
+
- ✅ Optionally disabled the old `zR` mapping
|
|
284
|
+
- ✅ Tested your new configuration
|
|
285
|
+
- ✅ Verified the mapping is active
|
|
286
|
+
|
|
287
|
+
Your new `zN` keymap is now part of your Neovim muscle memory. Use it consistently in your workflow.
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## Next Steps
|
|
292
|
+
|
|
293
|
+
1. Create this mapping in your actual `init.lua` right now
|
|
294
|
+
2. Test it for the next week in your daily editing
|
|
295
|
+
3. If you like it, consider adding the one-level mappings (`zn` and `zm`)
|
|
296
|
+
4. Move on to Exercise 17 when you're comfortable with fold navigation
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
## Resources
|
|
301
|
+
|
|
302
|
+
- `:help fold-commands` - Full fold command documentation
|
|
303
|
+
- `:help mapping` - Full mapping documentation
|
|
304
|
+
- `:help option-window` - View all fold-related options
|
|
305
|
+
- `:map` - List all current mappings
|
|
306
|
+
- `:verbose map zN` - See where a mapping is defined
|
|
307
|
+
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
**Keep it simple.** Just two lines for the basic mapping. Everything else is optional optimization.
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
# Customizing Fold Keymaps in Ariadna (zN instead of zR)
|
|
2
|
+
|
|
3
|
+
<!-- vim: set foldmethod=marker foldlevel=0: -->
|
|
4
|
+
|
|
5
|
+
## 📖 Ariadna Reading Guide {{{
|
|
6
|
+
|
|
7
|
+
**Start with:** `zM` (close all folds) → Navigate with `za` (toggle fold under cursor)
|
|
8
|
+
|
|
9
|
+
**Keys for navigation:**
|
|
10
|
+
- `}` - Jump to next section
|
|
11
|
+
- `{` - Jump to previous section
|
|
12
|
+
- `zM` - Close all folds (overview mode)
|
|
13
|
+
- `zN` - Open all folds (will use this after implementing!)
|
|
14
|
+
|
|
15
|
+
}}}
|
|
16
|
+
|
|
17
|
+
## 🎯 Purpose {{{
|
|
18
|
+
|
|
19
|
+
**What:** Replace Neovim's default fold keymaps with more intuitive ones
|
|
20
|
+
**Why:** The default `zR` is cryptic; `zN` (for "opeN") is more memorable
|
|
21
|
+
**Time:** 10 minutes
|
|
22
|
+
**Level:** 🟢 Beginner
|
|
23
|
+
**Entrypoint for ariadna setup:** `~/.config/nvim/lua/plugins/`
|
|
24
|
+
|
|
25
|
+
}}}
|
|
26
|
+
|
|
27
|
+
## Part 1: Understanding Default Fold Commands {{{
|
|
28
|
+
|
|
29
|
+
### Why Fold Commands Matter {{{
|
|
30
|
+
|
|
31
|
+
Ariadna uses fold markers (`{{{` and `}}}`) throughout documentation to create navigable sections. But the default Neovim keymaps are cryptic:
|
|
32
|
+
|
|
33
|
+
- `zR` = unfold all (Reduce? No one knows...)
|
|
34
|
+
- `zM` = fold all (More folds? Still confusing!)
|
|
35
|
+
- `zr` = unfold one level
|
|
36
|
+
- `zm` = fold one level
|
|
37
|
+
|
|
38
|
+
These follow old Vi conventions, not modern mnemonics.
|
|
39
|
+
|
|
40
|
+
}}}
|
|
41
|
+
|
|
42
|
+
### The Better Alternative {{{
|
|
43
|
+
|
|
44
|
+
We want:
|
|
45
|
+
- `zN` = unfold all (N for "**opeN**")
|
|
46
|
+
- `zM` = fold all (M for "**More** closed" - keep this)
|
|
47
|
+
- `zn` = unfold one level (lowercase n)
|
|
48
|
+
- `zm` = fold one level (lowercase m)
|
|
49
|
+
|
|
50
|
+
This is much more memorable and aligns with your muscle memory.
|
|
51
|
+
|
|
52
|
+
}}}
|
|
53
|
+
|
|
54
|
+
}}}
|
|
55
|
+
|
|
56
|
+
## Part 2: Creating the Plugin File {{{
|
|
57
|
+
|
|
58
|
+
### Step 1: Create the Folds Plugin {{{
|
|
59
|
+
|
|
60
|
+
Create a new file in Ariadna's plugin directory:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
nvim ~/.config/nvim/lua/plugins/folds.lua
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
This is where all Ariadna plugins live. LazyVim auto-loads every `.lua` file in this directory.
|
|
67
|
+
|
|
68
|
+
}}}
|
|
69
|
+
|
|
70
|
+
### Step 2: Add the Configuration {{{
|
|
71
|
+
|
|
72
|
+
Add this to `folds.lua`:
|
|
73
|
+
|
|
74
|
+
```lua
|
|
75
|
+
-- Custom fold keymaps for Ariadna
|
|
76
|
+
-- Replace cryptic zR/zM with intuitive zN/zM
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
{
|
|
80
|
+
"fold-keymaps/custom",
|
|
81
|
+
init = function()
|
|
82
|
+
local map = vim.keymap.set
|
|
83
|
+
|
|
84
|
+
-- Main fold commands
|
|
85
|
+
map("n", "zN", "zR", { desc = "Unfold all (zN = opeN)" })
|
|
86
|
+
map("n", "zM", "zM", { desc = "Fold all (zM = More closed)" })
|
|
87
|
+
|
|
88
|
+
-- Optional: One-level fold/unfold
|
|
89
|
+
map("n", "zn", "zr", { desc = "Unfold one level" })
|
|
90
|
+
map("n", "zm", "zm", { desc = "Fold one level" })
|
|
91
|
+
|
|
92
|
+
-- Optional: Disable zR to force zN usage
|
|
93
|
+
-- Uncomment if you want to completely replace zR
|
|
94
|
+
-- map("n", "zR", "<nop>", { desc = "Use zN instead (unfold all)" })
|
|
95
|
+
end,
|
|
96
|
+
},
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**What each mapping does:**
|
|
101
|
+
- `map("n", "zN", "zR", ...)` - In Normal mode, pressing `zN` executes `zR` (unfold all)
|
|
102
|
+
- `desc` - Help text for `:map zN` or which-key
|
|
103
|
+
|
|
104
|
+
}}}
|
|
105
|
+
|
|
106
|
+
### Step 3: Save and Reload {{{
|
|
107
|
+
|
|
108
|
+
In Neovim:
|
|
109
|
+
|
|
110
|
+
```vim
|
|
111
|
+
:w " Save folds.lua
|
|
112
|
+
:source % " Reload configuration
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Or exit and restart Neovim - LazyVim will auto-load the new plugin.
|
|
116
|
+
|
|
117
|
+
}}}
|
|
118
|
+
|
|
119
|
+
}}}
|
|
120
|
+
|
|
121
|
+
## Part 3: Testing Your Custom Keymaps {{{
|
|
122
|
+
|
|
123
|
+
### Test Zone: Try Your New Keymaps {{{
|
|
124
|
+
|
|
125
|
+
Now that you've created `folds.lua`, test it:
|
|
126
|
+
|
|
127
|
+
1. **Fold all content:**
|
|
128
|
+
Press `zM` (or `zm zm zm...` to fold level by level)
|
|
129
|
+
|
|
130
|
+
2. **Unfold all content:**
|
|
131
|
+
Press `zN` (this is your new mapping!)
|
|
132
|
+
|
|
133
|
+
3. **Verify it works:**
|
|
134
|
+
Check the output shows all sections visible again
|
|
135
|
+
|
|
136
|
+
4. **One-level folds:**
|
|
137
|
+
Try `zn` (unfold one level) and `zm` (fold one level)
|
|
138
|
+
|
|
139
|
+
The keymaps should respond immediately. If they don't:
|
|
140
|
+
- Did you save `folds.lua`?
|
|
141
|
+
- Did you reload nvim?
|
|
142
|
+
- Check: `:map zN` should show the mapping
|
|
143
|
+
|
|
144
|
+
}}}
|
|
145
|
+
|
|
146
|
+
### Advanced: Verify the Mapping {{{
|
|
147
|
+
|
|
148
|
+
In Neovim, run:
|
|
149
|
+
|
|
150
|
+
```vim
|
|
151
|
+
:map zN
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
You should see output like:
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
n zN zR
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
This confirms `zN` is mapped to `zR` (unfold all). If nothing shows, the mapping didn't load.
|
|
161
|
+
|
|
162
|
+
}}}
|
|
163
|
+
|
|
164
|
+
}}}
|
|
165
|
+
|
|
166
|
+
## Part 4: Ariadna-Specific Context {{{
|
|
167
|
+
|
|
168
|
+
### Why This Matters for Ariadna Users {{{
|
|
169
|
+
|
|
170
|
+
Ariadna documents are built with fold markers for optimal navigation:
|
|
171
|
+
|
|
172
|
+
```lua
|
|
173
|
+
-- These fold markers structure everything
|
|
174
|
+
-- {{{ = start fold
|
|
175
|
+
-- }}} = end fold
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
When you're reading Ariadna docs or editing structured Lua files, you'll:
|
|
179
|
+
|
|
180
|
+
1. Start with `zM` (fold all) to see structure
|
|
181
|
+
2. Navigate with `}` to jump sections
|
|
182
|
+
3. Use `za` to toggle individual folds
|
|
183
|
+
4. Use `zN` to unfold everything when you need full content
|
|
184
|
+
|
|
185
|
+
This is the "Ariadna way" of reading documentation.
|
|
186
|
+
|
|
187
|
+
}}}
|
|
188
|
+
|
|
189
|
+
### Where You'll Use This {{{
|
|
190
|
+
|
|
191
|
+
Every Ariadna document uses this pattern:
|
|
192
|
+
|
|
193
|
+
- `01-developing-muscle-for-nvim.md` - Has fold markers
|
|
194
|
+
- `15-nvim-plugin-architecture.md` - Heavily folded
|
|
195
|
+
- Your own `.md` files - You'll add fold markers too
|
|
196
|
+
|
|
197
|
+
Plus any Lua files you write in `~/.config/nvim/lua/` will benefit from custom fold navigation.
|
|
198
|
+
|
|
199
|
+
}}}
|
|
200
|
+
|
|
201
|
+
}}}
|
|
202
|
+
|
|
203
|
+
## Part 5: Optional Customizations {{{
|
|
204
|
+
|
|
205
|
+
### Option 1: Disable Old zR Mapping {{{
|
|
206
|
+
|
|
207
|
+
If you want to completely replace `zR` with `zN` (force new muscle memory):
|
|
208
|
+
|
|
209
|
+
**Edit** `~/.config/nvim/lua/plugins/folds.lua`:
|
|
210
|
+
|
|
211
|
+
```lua
|
|
212
|
+
-- Disable zR to force zN usage
|
|
213
|
+
map("n", "zR", "<nop>", { desc = "Use zN instead" })
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
This makes `zR` do nothing, so you're forced to use `zN`.
|
|
217
|
+
|
|
218
|
+
}}}
|
|
219
|
+
|
|
220
|
+
### Option 2: Add Custom Fold Default Level {{{
|
|
221
|
+
|
|
222
|
+
You can set the default fold level when opening files:
|
|
223
|
+
|
|
224
|
+
```lua
|
|
225
|
+
vim.opt.foldlevel = 1 -- Start with one level open
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Add this to `~/.config/nvim/lua/config/options.lua` (or create a new section in folds.lua):
|
|
229
|
+
|
|
230
|
+
```lua
|
|
231
|
+
init = function()
|
|
232
|
+
-- Set default fold behavior
|
|
233
|
+
vim.opt.foldlevel = 1
|
|
234
|
+
vim.opt.foldmethod = "marker" -- Use {{{ }}} markers
|
|
235
|
+
end
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
}}}
|
|
239
|
+
|
|
240
|
+
### Option 3: Add Smart Fold Toggle {{{
|
|
241
|
+
|
|
242
|
+
Create a function that intelligently toggles between fold all/unfold all:
|
|
243
|
+
|
|
244
|
+
```lua
|
|
245
|
+
local function smart_fold_toggle()
|
|
246
|
+
local fold_level = vim.fn.foldlevel(vim.fn.line('.'))
|
|
247
|
+
if fold_level > 0 then
|
|
248
|
+
vim.cmd('zN') -- Unfold all
|
|
249
|
+
else
|
|
250
|
+
vim.cmd('zM') -- Fold all
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
map("n", "z<Space>", smart_fold_toggle, { desc = "Smart fold toggle" })
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Now `z<Space>` intelligently switches between folded/unfolded state.
|
|
258
|
+
|
|
259
|
+
}}}
|
|
260
|
+
|
|
261
|
+
}}}
|
|
262
|
+
|
|
263
|
+
## Part 6: Troubleshooting {{{
|
|
264
|
+
|
|
265
|
+
### Mapping Doesn't Work {{{
|
|
266
|
+
|
|
267
|
+
**Problem:** You press `zN` and nothing happens.
|
|
268
|
+
|
|
269
|
+
**Solutions:**
|
|
270
|
+
1. Verify mapping loaded: `:map zN` (should show output)
|
|
271
|
+
2. Reload config: `:source %` or restart nvim
|
|
272
|
+
3. Check you're in Normal mode (press `Esc` first)
|
|
273
|
+
4. Verify `folds.lua` file exists: `ls ~/.config/nvim/lua/plugins/folds.lua`
|
|
274
|
+
|
|
275
|
+
}}}
|
|
276
|
+
|
|
277
|
+
### Old zR Mapping Still Works {{{
|
|
278
|
+
|
|
279
|
+
**Problem:** `zR` still unfolds even though you wanted to disable it.
|
|
280
|
+
|
|
281
|
+
**Solutions:**
|
|
282
|
+
1. Make sure you added the `<nop>` mapping in `folds.lua`
|
|
283
|
+
2. Restart Neovim completely (`:q!` then `nvim`)
|
|
284
|
+
3. Check for conflicts: `:verbose map zR`
|
|
285
|
+
|
|
286
|
+
}}}
|
|
287
|
+
|
|
288
|
+
### File Has No Folds {{{
|
|
289
|
+
|
|
290
|
+
**Problem:** `zM` doesn't do anything.
|
|
291
|
+
|
|
292
|
+
**Solutions:**
|
|
293
|
+
1. File must use fold markers: `{{{` and `}}}`
|
|
294
|
+
2. Set foldmethod: `:set foldmethod=marker`
|
|
295
|
+
3. Try on an Ariadna document that has fold markers
|
|
296
|
+
|
|
297
|
+
}}}
|
|
298
|
+
|
|
299
|
+
}}}
|
|
300
|
+
|
|
301
|
+
## 🎯 Outcomes {{{
|
|
302
|
+
|
|
303
|
+
After this exercise, you can:
|
|
304
|
+
|
|
305
|
+
✅ Create custom Neovim keymaps in Ariadna plugin files
|
|
306
|
+
✅ Replace cryptic default keymaps with intuitive ones
|
|
307
|
+
✅ Use `zN` instead of `zR` for "open" all folds
|
|
308
|
+
✅ Structure your Lua files with fold markers for navigation
|
|
309
|
+
✅ Read Ariadna documentation using fold navigation
|
|
310
|
+
✅ Customize Ariadna's behavior without forking the repo
|
|
311
|
+
✅ Debug and verify custom keymaps with `:map`
|
|
312
|
+
|
|
313
|
+
**Your new workflow:**
|
|
314
|
+
- `zM` - Fold all (see structure)
|
|
315
|
+
- `}` - Jump to next section
|
|
316
|
+
- `za` - Toggle individual fold
|
|
317
|
+
- `zN` - Unfold all (see content)
|
|
318
|
+
|
|
319
|
+
**Next Steps:**
|
|
320
|
+
- Try the custom `zN` mapping in actual Ariadna files
|
|
321
|
+
- Add fold markers to your own documentation
|
|
322
|
+
- Experiment with one-level folds (`zn`/`zm`)
|
|
323
|
+
- Move on to Exercise 18 when comfortable
|
|
324
|
+
|
|
325
|
+
}}}
|
|
326
|
+
|
|
327
|
+
## 🧭 Reference Links {{{
|
|
328
|
+
|
|
329
|
+
**Ariadna Locations:**
|
|
330
|
+
- Plugin files: `~/.config/nvim/lua/plugins/`
|
|
331
|
+
- Core settings: `~/.config/nvim/lua/config/`
|
|
332
|
+
- Your config: `~/.config/nvim/init.lua`
|
|
333
|
+
|
|
334
|
+
**Neovim Documentation:**
|
|
335
|
+
- `:help fold-commands` - Full fold documentation
|
|
336
|
+
- `:help map` - Mapping documentation
|
|
337
|
+
- `:help foldmethod` - Fold detection options
|
|
338
|
+
|
|
339
|
+
**Vim Mnemonics:**
|
|
340
|
+
- `z` = zones (folds)
|
|
341
|
+
- `N` = ope**N** (unfold all)
|
|
342
|
+
- `M` = **M**ore folds (fold all)
|
|
343
|
+
- `n` = ope**n** (unfold one level)
|
|
344
|
+
- `m` = **m**ore folds (fold one level)
|
|
345
|
+
|
|
346
|
+
**Related Exercises:**
|
|
347
|
+
- Exercise 01 - Developing Muscle Memory (uses fold navigation)
|
|
348
|
+
- Exercise 15 - LazyVim Plugin Architecture (plugin structure)
|
|
349
|
+
|
|
350
|
+
}}}
|
|
351
|
+
|
|
352
|
+
## 📝 Quick Reference: What You Just Created {{{
|
|
353
|
+
|
|
354
|
+
**File:** `~/.config/nvim/lua/plugins/folds.lua`
|
|
355
|
+
|
|
356
|
+
**What it does:**
|
|
357
|
+
1. Maps `zN` to `zR` (unfold all)
|
|
358
|
+
2. Maps `zM` to `zM` (fold all - no change needed)
|
|
359
|
+
3. Maps `zn` to `zr` (unfold one level - optional)
|
|
360
|
+
4. Maps `zm` to `zm` (fold one level - optional)
|
|
361
|
+
|
|
362
|
+
**How to modify:**
|
|
363
|
+
- Edit the file and save
|
|
364
|
+
- Reload: `:source %` or restart nvim
|
|
365
|
+
- Verify: `:map zN`
|
|
366
|
+
|
|
367
|
+
**How to remove:**
|
|
368
|
+
```bash
|
|
369
|
+
rm ~/.config/nvim/lua/plugins/folds.lua
|
|
370
|
+
# Then restart nvim
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
}}}
|