@@ -23,14 +23,29 @@ every keybind bit by bit.
2323["core.keybinds"] = {
2424 config = {
2525 hook = function(keybinds)
26+ -- Unmaps any Neorg key from the `norg` mode
2627 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>")
2740 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")
2845 end,
2946 }
3047}
3148```
32-
33- TODO: Perhaps autogenerate all the functions `keybinds` exposes.
3449--]]
3550
3651require (" neorg.modules.base" )
@@ -109,16 +124,16 @@ module.examples = {
109124 end )
110125
111126 -- 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.
114129 end ,
115130}
116131
117132module .setup = function ()
118133 return {
119134 success = true ,
120135 requires = { " core.neorgcmd" , " core.mode" , " core.autocommands" },
121- imports = { " default_keybinds " },
136+ imports = { " keybinds " },
122137 }
123138end
124139
@@ -134,7 +149,7 @@ module.load = function()
134149end
135150
136151module .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
138153 default_keybinds = true ,
139154
140155 -- Prefix for some Neorg keybinds
@@ -224,12 +239,12 @@ module.public = {
224239
225240 payload = {
226241
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`
233248 map = function (neorg_mode , mode , key , command , opts )
234249 bound_keys [neorg_mode ] = bound_keys [neorg_mode ] or {}
235250 bound_keys [neorg_mode ][mode ] = bound_keys [neorg_mode ][mode ] or {}
@@ -241,10 +256,22 @@ module.public = {
241256 }
242257 end ,
243258
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`
244267 map_event = function (neorg_mode , mode , key , expr , opts )
245268 payload .map (neorg_mode , mode , key , " <cmd>Neorg keybind " .. neorg_mode .. " " .. expr .. " <CR>" , opts )
246269 end ,
247270
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
248275 unmap = function (neorg_mode , mode , key )
249276 if neorg_mode == " all" then
250277 for _ , norg_mode in ipairs (module .required [" core.mode" ].get_modes ()) do
@@ -342,7 +369,7 @@ module.public = {
342369 end
343370 end ,
344371
345- -- Include the current Neorg mode in the contents
372+ -- Include the current Neorg mode and leader in the contents
346373 mode = current_mode ,
347374 leader = module .config .public .neorg_leader ,
348375 }
0 commit comments