From cab110323308130fad71ad882a31f10e5bf47a4b Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 6 Jan 2024 14:06:57 +0100 Subject: [PATCH] feat(keybind-rewrite): format and update docs --- lua/neorg/modules/core/keybinds/keybinds.lua | 10 ---- lua/neorg/modules/core/keybinds/module.lua | 60 ++++++++++---------- 2 files changed, 30 insertions(+), 40 deletions(-) diff --git a/lua/neorg/modules/core/keybinds/keybinds.lua b/lua/neorg/modules/core/keybinds/keybinds.lua index 70399d770..83b195da8 100644 --- a/lua/neorg/modules/core/keybinds/keybinds.lua +++ b/lua/neorg/modules/core/keybinds/keybinds.lua @@ -15,7 +15,6 @@ module.config.public = { -- Marks the task under the cursor as "undone" -- ^mark Task as Undone [leader .. "tu"] = { - "core.qol.todo_items.todo.task_undone", opts = { desc = "Mark as Undone" }, }, @@ -23,7 +22,6 @@ module.config.public = { -- Marks the task under the cursor as "pending" -- ^mark Task as Pending [leader .. "tp"] = { - "core.qol.todo_items.todo.task_pending", opts = { desc = "Mark as Pending" }, }, @@ -35,7 +33,6 @@ module.config.public = { -- Marks the task under the cursor as "on_hold" -- ^mark Task as on Hold [leader .. "th"] = { - "core.qol.todo_items.todo.task_on_hold", opts = { desc = "Mark as On Hold" }, }, @@ -43,7 +40,6 @@ module.config.public = { -- Marks the task under the cursor as "cancelled" -- ^mark Task as Cancelled [leader .. "tc"] = { - "core.qol.todo_items.todo.task_cancelled", opts = { desc = "Mark as Cancelled" }, }, @@ -51,7 +47,6 @@ module.config.public = { -- Marks the task under the cursor as "recurring" -- ^mark Task as Recurring [leader .. "tr"] = { - "core.qol.todo_items.todo.task_recurring", opts = { desc = "Mark as Recurring" }, }, @@ -59,7 +54,6 @@ module.config.public = { -- Marks the task under the cursor as "important" -- ^mark Task as Important [leader .. "ti"] = { - "core.qol.todo_items.todo.task_important", opts = { desc = "Mark as Important" }, }, @@ -67,7 +61,6 @@ module.config.public = { -- Marks the task under the cursor as "ambiguous" -- ^mark Task as ambiguous [leader .. "ta"] = { - "core.qol.todo_items.todo.task_ambiguous", opts = { desc = "Mark as Ambigous" }, }, @@ -87,7 +80,6 @@ module.config.public = { -- Same as ``, except opens the destination in a vertical split [""] = { - "core.esupports.hop.hop-link", "vsplit", opts = { desc = "Jump to Link (Vertical Split)" }, @@ -100,12 +92,10 @@ module.config.public = { ["<<"] = { "core.promo.demote", "nested", opts = { desc = "Demote Object (Recursively)" } }, [leader .. "lt"] = { - "core.pivot.toggle-list-type", opts = { desc = "Toggle (Un)ordered List" }, }, [leader .. "li"] = { - "core.pivot.invert-list-type", opts = { desc = "Invert (Un)ordered List" }, }, diff --git a/lua/neorg/modules/core/keybinds/module.lua b/lua/neorg/modules/core/keybinds/module.lua index 9957dcc76..4da7ec7e9 100644 --- a/lua/neorg/modules/core/keybinds/module.lua +++ b/lua/neorg/modules/core/keybinds/module.lua @@ -8,10 +8,6 @@ The keybind module acts as both an interface to the user and as an interface to External modules can ask `core.keybinds` to reserve a specific keybind name, after which `core.keybinds` passes control to you (the user) to specify what key this should be bound to. -Because of this client/server model, you must define your own `hook` function, which can -set/overwrite several keybindings to your personal preference. Below is some information -on how to disable keybinds and how to set up a keybind hook. - ### Disabling Default Keybinds By default when you load the `core.keybinds` module all keybinds will be enabled. If you would like to change this, be sure to set `default_keybinds` to `false`: @@ -23,35 +19,35 @@ If you would like to change this, be sure to set `default_keybinds` to `false`: } ``` -### Setting Up a Keybind Hook -To change some keybinds, you must set up a keybind hook. Below is an example -on how to do so, alongside a bunch of functions exposed to you that you can invoke -to finely control what gets set and where: +### Changing keybinds +To change keybinds you can use the `overwrite` field in the config which is a table. +To look at the default keybinds and also the structure of this table you should refer to +[this file](https://github.com/nvim-neorg/neorg/blob/main/lua/neorg/modules/core/keybinds/keybinds.lua). +To disable a keybinding set it's value in the table to `nil` or an empty table (`{}`). +To add a new keybinding provide a function. This can either be the first value in a table +where you can also provide an `opts` field or just the value of the field directly. + +If you use a string that will be interpreted as an argument to the neorg keybind command +`:Neorg keybind `. ```lua ["core.keybinds"] = { config = { - hook = function(keybinds) - -- Unmaps any Neorg key from the `norg` mode - keybinds.unmap("norg", "n", "gtd") - keybinds.unmap("norg", "n", keybinds.leader .. "nn") - - -- Binds the `gtd` key in `norg` mode to execute `:echo 'Hello'` - keybinds.map("norg", "n", "gtd", "echo 'Hello!'") - - -- Remap unbinds the current key then rebinds it to have a different action - -- associated with it. - -- The following is the equivalent of the `unmap` and `map` calls you saw above: - keybinds.remap("norg", "n", "gtd", "echo 'Hello!'") - - -- Sometimes you may simply want to rebind the Neorg action something is bound to - -- versus remapping the entire keybind. This remap is essentially the same as if you - -- did `keybinds.remap("norg", "n", ", "Neorg keybind norg core.qol.todo_items.todo.task_done") - keybinds.remap_event("norg", "n", "", "core.qol.todo_items.todo.task_done") - - -- Want to move one keybind into the other? `remap_key` moves the data of the - -- first keybind to the second keybind, then unbinds the first keybind. - keybinds.remap_key("norg", "n", "", "t") - end, + overwrite = { + norg = { + n = { + -- Disable keybinding + [""] = nil, + + -- Create a new keybinding to tangle the current file + [",TC"] = { + function() + vim.cmd.Neorg({ args = { "tangle", "current-file" } }) + end, + opts = { desc = "Tangle current file" }, + }, + } + } + } } } ``` @@ -93,6 +89,7 @@ module.config.public = { -- By default, this is the local leader key, which you must bind manually. neorg_leader = "", + -- Keybinds which will be overwritten overwrite = {}, -- The keybind preset to use. @@ -178,6 +175,9 @@ module.public = { for mode, keys in pairs(neovim_modes) do for key, data in pairs(keys) do local ok, error = pcall(function() + if data == nil or #data == 0 then + return + end local rhs if type(data) == "function" then rhs = data