@@ -23,14 +23,29 @@ every keybind bit by bit.
23
23
["core.keybinds"] = {
24
24
config = {
25
25
hook = function(keybinds)
26
+ -- Unmaps any Neorg key from the `norg` mode
26
27
keybinds.unmap("norg", "n", "gtd")
28
+
29
+ -- Binds the `gtd` key in `norg` mode to execute `:echo 'Hello'`
30
+ keybinds.map("norg", "n", "gtd", "<cmd>echo 'Hello!'<CR>")
31
+
32
+ -- Remap unbinds the current key then rebinds it to have a different action
33
+ -- associated with it.
34
+ -- The following is the equivalent of the `unmap` and `map` calls you saw above:
35
+ keybinds.remap("norg", "n", "gtd", "<cmd>echo 'Hello!'<CR>")
36
+
37
+ -- Sometimes you may simply want to rebind the Neorg action something is bound to
38
+ -- versus remapping the entire keybind. This remap is essentially the same as if you
39
+ -- did `keybinds.remap("norg", "n", "<C-Space>, "<cmd>Neorg keybind norg core.norg.qol.todo_items.todo.task_done<CR>")
27
40
keybinds.remap_event("norg", "n", "<C-Space>", "core.norg.qol.todo_items.todo.task_done")
41
+
42
+ -- Want to move one keybind into the other? `remap_key` moves the data of the
43
+ -- first keybind to the second keybind, then unbinds the first keybind.
44
+ keybinds.remap_key("norg", "n", "<C-Space>", "<Leader>t")
28
45
end,
29
46
}
30
47
}
31
48
```
32
-
33
- TODO: Perhaps autogenerate all the functions `keybinds` exposes.
34
49
--]]
35
50
36
51
require (" neorg.modules.base" )
@@ -109,16 +124,16 @@ module.examples = {
109
124
end )
110
125
111
126
-- To change the current mode as a user of neorg you can run :Neorg set-mode <mode>.
112
- -- If you try changing the current mode into a non-existent mode (like :Neorg set-mode a-nonexistent-mode) you will see that all the keybinds you bound to the norg mode won't work anymore!
113
- -- They'll start working again if you reset the mode back via :Neorg set-mode norg.
127
+ -- If you try changing the current mode into a non-existent mode (like :Neorg set-mode a-nonexistent-mode) you will see that all the keybinds you bound to the norg mode won't work anymore!
128
+ -- They'll start working again if you reset the mode back via :Neorg set-mode norg.
114
129
end ,
115
130
}
116
131
117
132
module .setup = function ()
118
133
return {
119
134
success = true ,
120
135
requires = { " core.neorgcmd" , " core.mode" , " core.autocommands" },
121
- imports = { " default_keybinds " },
136
+ imports = { " keybinds " },
122
137
}
123
138
end
124
139
@@ -134,7 +149,7 @@ module.load = function()
134
149
end
135
150
136
151
module .config .public = {
137
- -- Use the default keybinds provided in https://github.com/nvim-neorg/neorg/blob/main/lua/neorg/modules/core/keybinds/default_keybinds .lua
152
+ -- Use the default keybinds provided in https://github.com/nvim-neorg/neorg/blob/main/lua/neorg/modules/core/keybinds/keybinds .lua
138
153
default_keybinds = true ,
139
154
140
155
-- Prefix for some Neorg keybinds
@@ -224,12 +239,12 @@ module.public = {
224
239
225
240
payload = {
226
241
227
- -- @Summary Maps a Neovim keybind.
228
- -- @Description Allows Neorg to manage and track mapped keys.
229
- -- @Param mode ( string) - same as the mode parameter for :h nvim_buf_set_keymap
230
- -- @Param key ( string) - same as the lhs parameter for :h nvim_buf_set_keymap
231
- -- @Param command ( string) - same as the rhs parameter for :h nvim_buf_set_keymap
232
- -- @Param opts ( table) - same as the opts parameter for :h nvim_buf_set_keymap
242
+ --- Maps a key to a specific Neorg mode
243
+ --- @param neorg_mode string #The Neorg mode to bind to
244
+ --- @param mode string #The Neovim mode to bind to, e.g. `n` or `i` etc.
245
+ --- @param key string #The lhs value from ` :h nvim_buf_set_keymap`
246
+ --- @param command string | function #The rhs value from ` :h nvim_buf_set_keymap`
247
+ --- @param opts table #The table value from ` :h nvim_buf_set_keymap`
233
248
map = function (neorg_mode , mode , key , command , opts )
234
249
bound_keys [neorg_mode ] = bound_keys [neorg_mode ] or {}
235
250
bound_keys [neorg_mode ][mode ] = bound_keys [neorg_mode ][mode ] or {}
@@ -241,10 +256,22 @@ module.public = {
241
256
}
242
257
end ,
243
258
259
+ --- Maps a key to a specific Neorg keybind.
260
+ -- `map()` binds to any rhs value, whilst `map_event()` is essentially a wrapper
261
+ -- for <cmd>Neorg keybind `neorg_mode` `expr`<CR>
262
+ --- @param neorg_mode string #The Neorg mode to bind to
263
+ --- @param mode string #The Neovim mode to bind to, e.g. `n` or `i` etc.
264
+ --- @param key string #The lhs value from `:h nvim_buf_set_keymap`
265
+ --- @param expr string #The Neorg event to bind to (e.g. `core.norg.dirman.new.note`)
266
+ --- @param opts table #The table value from `:h nvim_buf_set_keymap`
244
267
map_event = function (neorg_mode , mode , key , expr , opts )
245
268
payload .map (neorg_mode , mode , key , " <cmd>Neorg keybind " .. neorg_mode .. " " .. expr .. " <CR>" , opts )
246
269
end ,
247
270
271
+ --- Unmaps any keybind from any Neorg mode
272
+ --- @param neorg_mode string #The Neorg mode to remove the key from
273
+ --- @param mode string #The target Neovim mode
274
+ --- @param key string #The key itself to unmap
248
275
unmap = function (neorg_mode , mode , key )
249
276
if neorg_mode == " all" then
250
277
for _ , norg_mode in ipairs (module .required [" core.mode" ].get_modes ()) do
@@ -342,7 +369,7 @@ module.public = {
342
369
end
343
370
end ,
344
371
345
- -- Include the current Neorg mode in the contents
372
+ -- Include the current Neorg mode and leader in the contents
346
373
mode = current_mode ,
347
374
leader = module .config .public .neorg_leader ,
348
375
}
0 commit comments