diff --git a/lua/neorg/modules/core/keybinds/module.lua b/lua/neorg/modules/core/keybinds/module.lua index 4357af7d6..88fb8164b 100644 --- a/lua/neorg/modules/core/keybinds/module.lua +++ b/lua/neorg/modules/core/keybinds/module.lua @@ -13,151 +13,171 @@ local module = modules.create("core.keybinds") module.load = function() if module.config.public.default_keybinds then - local preset = module.private.presets[module.config.public.preset] - assert(preset, string.format("keybind preset `%s` does not exist!", module.config.public.preset)) + vim.api.nvim_create_autocmd("BufEnter", { + callback = function() + local is_norg = vim.bo.filetype == "norg" + + local preset = module.private.presets[module.config.public.preset] + assert(preset, string.format("keybind preset `%s` does not exist!", module.config.public.preset)) + + local function set_keys_for(data) + for mode, keybinds in pairs(data) do + for _, keybind in ipairs(keybinds) do + if vim.fn.hasmapto(keybind[2], mode, false) == 0 then + local opts = vim.tbl_deep_extend("force", { buffer = true }, keybinds.opts or {}) + vim.keymap.set(mode, keybind[1], keybind[2], opts) + end + end + end + end + + set_keys_for(preset.all) - for mode, keybinds in pairs(preset) do - for _, keybind in ipairs(keybinds) do - if vim.fn.hasmapto(keybind[2], mode, false) == 0 then - vim.keymap.set(mode, keybind[1], keybind[2], keybind.opts or {}) + if is_norg then + set_keys_for(preset.norg) end - end - end + end, + }) end end module.private = { presets = { neorg = { - n = { - -- Marks the task under the cursor as "undone" - -- ^mark Task as Undone - { - "tu", - "(neorg.qol.todo-items.todo.task-undone)", - opts = { desc = "[neorg] Mark as Undone" }, - }, - - -- Marks the task under the cursor as "pending" - -- ^mark Task as Pending - { - "tp", - "(neorg.qol.todo-items.todo.task-pending)", - opts = { desc = "[neorg] Mark as Pending" }, - }, - - -- Marks the task under the cursor as "done" - -- ^mark Task as Done - { - "td", - "(neorg.qol.todo-items.todo.task-done)", - opts = { desc = "[neorg] Mark as Done" }, - }, - - -- Marks the task under the cursor as "on-hold" - -- ^mark Task as on Hold - { - "th", - "(neorg.qol.todo-items.todo.task-on-hold)", - opts = { desc = "[neorg] Mark as On Hold" }, - }, - - -- Marks the task under the cursor as "cancelled" - -- ^mark Task as Cancelled - { - "tc", - "(neorg.qol.todo-items.todo.task-cancelled)", - opts = { desc = "[neorg] Mark as Cancelled" }, - }, - - -- Marks the task under the cursor as "recurring" - -- ^mark Task as Recurring - { - "tr", - "(neorg.qol.todo-items.todo.task-recurring)", - opts = { desc = "[neorg] Mark as Recurring" }, - }, - - -- Marks the task under the cursor as "important" - -- ^mark Task as Important - { - "ti", - "(neorg.qol.todo-items.todo.task-important)", - opts = { desc = "[neorg] Mark as Important" }, - }, - - -- Marks the task under the cursor as "ambiguous" - -- ^mark Task as ambiguous - { - "ta", - "(neorg.qol.todo-items.todo.task-ambiguous)", - opts = { desc = "[neorg] Mark as Ambigous" }, - }, - - -- Switches the task under the cursor between a select few states - { - "", - "(neorg.qol.todo-items.todo.task-cycle)", - opts = { desc = "[neorg] Cycle Task" }, - }, - - -- Creates a new .norg file to take notes in - -- ^New Note - { - "nn", - "(neorg.dirman.new-note)", - opts = { desc = "[neorg] Create New Note" }, + all = { + n = { + -- Creates a new .norg file to take notes in + -- ^New Note + { + "nn", + "(neorg.dirman.new-note)", + opts = { desc = "[neorg] Create New Note" }, + }, }, - - -- Hop to the destination of the link under the cursor - { "", "(neorg.esupports.hop.hop-link)", opts = { desc = "[neorg] Jump to Link" } }, - -- TODO: Move these to the "vim" preset - -- { "gd", "(neorg.esupports.hop.hop-link)", opts = { desc = "[neorg] Jump to Link" } }, - -- { "gf", "(neorg.esupports.hop.hop-link)", opts = { desc = "[neorg] Jump to Link" } }, - -- { "gF", "(neorg.esupports.hop.hop-link)", opts = { desc = "[neorg] Jump to Link" } }, - - -- Same as ``, except opens the destination in a vertical split - { - "", - "(neorg.esupports.hop.hop-link.vsplit)", - opts = { desc = "[neorg] Jump to Link (Vertical Split)" }, + }, + norg = { + n = { + -- Marks the task under the cursor as "undone" + -- ^mark Task as Undone + { + "tu", + "(neorg.qol.todo-items.todo.task-undone)", + opts = { desc = "[neorg] Mark as Undone" }, + }, + + -- Marks the task under the cursor as "pending" + -- ^mark Task as Pending + { + "tp", + "(neorg.qol.todo-items.todo.task-pending)", + opts = { desc = "[neorg] Mark as Pending" }, + }, + + -- Marks the task under the cursor as "done" + -- ^mark Task as Done + { + "td", + "(neorg.qol.todo-items.todo.task-done)", + opts = { desc = "[neorg] Mark as Done" }, + }, + + -- Marks the task under the cursor as "on-hold" + -- ^mark Task as on Hold + { + "th", + "(neorg.qol.todo-items.todo.task-on-hold)", + opts = { desc = "[neorg] Mark as On Hold" }, + }, + + -- Marks the task under the cursor as "cancelled" + -- ^mark Task as Cancelled + { + "tc", + "(neorg.qol.todo-items.todo.task-cancelled)", + opts = { desc = "[neorg] Mark as Cancelled" }, + }, + + -- Marks the task under the cursor as "recurring" + -- ^mark Task as Recurring + { + "tr", + "(neorg.qol.todo-items.todo.task-recurring)", + opts = { desc = "[neorg] Mark as Recurring" }, + }, + + -- Marks the task under the cursor as "important" + -- ^mark Task as Important + { + "ti", + "(neorg.qol.todo-items.todo.task-important)", + opts = { desc = "[neorg] Mark as Important" }, + }, + + -- Marks the task under the cursor as "ambiguous" + -- ^mark Task as ambiguous + { + "ta", + "(neorg.qol.todo-items.todo.task-ambiguous)", + opts = { desc = "[neorg] Mark as Ambigous" }, + }, + + -- Switches the task under the cursor between a select few states + { + "", + "(neorg.qol.todo-items.todo.task-cycle)", + opts = { desc = "[neorg] Cycle Task" }, + }, + + -- Hop to the destination of the link under the cursor + { "", "(neorg.esupports.hop.hop-link)", opts = { desc = "[neorg] Jump to Link" } }, + -- TODO: Move these to the "vim" preset + -- { "gd", "(neorg.esupports.hop.hop-link)", opts = { desc = "[neorg] Jump to Link" } }, + -- { "gf", "(neorg.esupports.hop.hop-link)", opts = { desc = "[neorg] Jump to Link" } }, + -- { "gF", "(neorg.esupports.hop.hop-link)", opts = { desc = "[neorg] Jump to Link" } }, + + -- Same as ``, except opens the destination in a vertical split + { + "", + "(neorg.esupports.hop.hop-link.vsplit)", + opts = { desc = "[neorg] Jump to Link (Vertical Split)" }, + }, + + { ">.", "(neorg.promo.promote)", opts = { desc = "[neorg] Promote Object (Non-Recursively)" } }, + { "<,", "(neorg.promo.demote)", opts = { desc = "[neorg] Demote Object (Non-Recursively)" } }, + + { + ">>", + "(neorg.promo.promote.nested)", + opts = { desc = "[neorg] Promote Object (Recursively)" }, + }, + { "<<", "(neorg.promo.demote.nested)", opts = { desc = "[neorg] Demote Object (Recursively)" } }, + + { + "lt", + "(neorg.pivot.list.toggle)", + opts = { desc = "[neorg] Toggle (Un)ordered List" }, + }, + { + "li", + "(neorg.pivot.list.invert)", + opts = { desc = "[neorg] Invert (Un)ordered List" }, + }, + + { "id", "(neorg.tempus.insert-date)", opts = { desc = "[neorg] Insert Date" } }, }, - { ">.", "(neorg.promo.promote)", opts = { desc = "[neorg] Promote Object (Non-Recursively)" } }, - { "<,", "(neorg.promo.demote)", opts = { desc = "[neorg] Demote Object (Non-Recursively)" } }, - - { - ">>", - "(neorg.promo.promote.nested)", - opts = { desc = "[neorg] Promote Object (Recursively)" }, + i = { + { "", "(neorg.promo.promote)", opts = { desc = "[neorg] Promote Object (Recursively)" } }, + { "", "(neorg.promo.demote)", opts = { desc = "[neorg] Demote Object (Recursively)" } }, + { "", "(neorg.itero.next-iteration)", opts = { desc = "[neorg] Continue Object" } }, + { "", "(neorg.tempus.insert-date-insert-mode)", opts = { desc = "[neorg] Insert Date" } }, }, - { "<<", "(neorg.promo.demote.nested)", opts = { desc = "[neorg] Demote Object (Recursively)" } }, - { - "lt", - "(neorg.pivot.list.toggle)", - opts = { desc = "[neorg] Toggle (Un)ordered List" }, + v = { + { ">", "(neorg.promo.promote.range)", opts = { desc = "[neorg] Promote Objects in Range" } }, + { "<", "(neorg.promo.demote.range)", opts = { desc = "[neorg] Demote Objects in Range" } }, }, - { - "li", - "(neorg.pivot.list.invert)", - opts = { desc = "[neorg] Invert (Un)ordered List" }, - }, - - { "id", "(neorg.tempus.insert-date)", opts = { desc = "[neorg] Insert Date" } }, - }, - - i = { - { "", "(neorg.promo.promote)", opts = { desc = "[neorg] Promote Object (Recursively)" } }, - { "", "(neorg.promo.demote)", opts = { desc = "[neorg] Demote Object (Recursively)" } }, - { "", "(neorg.itero.next-iteration)", opts = { desc = "[neorg] Continue Object" } }, - { "", "(neorg.tempus.insert-date-insert-mode)", opts = { desc = "[neorg] Insert Date" } }, - }, - - v = { - { ">", "(neorg.promo.promote.range)", opts = { desc = "[neorg] Promote Objects in Range" } }, - { "<", "(neorg.promo.demote.range)", opts = { desc = "[neorg] Demote Objects in Range" } }, - }, + } }, }, }