diff --git a/lua/config/keymaps.lua b/lua/config/keymaps.lua index a610b50..4e758ca 100644 --- a/lua/config/keymaps.lua +++ b/lua/config/keymaps.lua @@ -3,105 +3,181 @@ -- ╰─────────────────────────────────────────────────────────╯ -- Initialize which-key local wk = require("which-key") +local rootiest = require("config.rootiest") +local smartsplits = require("smart-splits") + +local all_modes = { "n", "i", "v", "x", "s", "o", "c", "t" } + +-- Helper function to add keymaps with common properties +local function add_keymap(lhs, rhs, desc, modes) + wk.add({ + { + lhs, + rhs = rhs, + desc = desc, + mode = modes or "n", -- default to normal mode if not specified + }, + }) +end + +-- General Keybinds +add_keymap("gt", function() + rootiest.toggle_lazygit_term() +end, "LazyGit Terminal") +add_keymap("yo", function() + rootiest.yank_line() +end, "Yank Line-text") +add_keymap("uH", function() + rootiest.toggle_hardmode() +end, "Toggle Hardmode") +add_keymap("Y", "%y", "Yank buffer contents") +add_keymap("|", "Neotree reveal", "Neotree reveal") + +-- Group Keybinds wk.add({ - { -- Open LazyGit in terminal - "gt", - rhs = function() - require("config.rootiest").toggle_lazygit_term() - end, - desc = "LazyGit Terminal", - }, - -- Icon Picker group { - mode = "n", lhs = "I", group = "IconPicker", icon = { icon = "󰥸", color = "orange" }, }, - -- Gists group { - mode = "n", lhs = "gn", group = "Gists", icon = { icon = "", color = "orange" }, }, - { -- Lazy group - "l", + { + lhs = "l", group = "Lazy", }, - { -- LazyVim + { "lv", "Lazy", desc = "LazyVim", }, - { -- LazyExtras + { "lx", "LazyExtras", desc = "LazyExtras", }, - { -- MiniMap - "m", + { + lhs = "m", group = "MiniMap", icon = { icon = "", color = "yellow" }, }, - { - "yo", - rhs = function() - require("config.rootiest").yank_line() - end, - desc = "Yank Line-text", - }, - { -- Toggle Hardmode with Hints - "uH", - rhs = function() - require("config.rootiest").toggle_hardmode() - end, - desc = "Toggle Hardmode", - }, { "u,", group = "Font" }, - { -- Yank buffer contents - "Y", - "%y", - desc = "Yank buffer contents", - }, }) --- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━ smart-splits ━━━━━━━━━━━━━━━━━━━━━━━━━ --- recommended mappings --- resizing splits --- these keymaps will also accept a range, --- for example `10` will `resize_left` by `(10 * config.default_amount)` -vim.keymap.set("n", "", require("smart-splits").resize_left) -vim.keymap.set("n", "", require("smart-splits").resize_down) -vim.keymap.set("n", "", require("smart-splits").resize_up) -vim.keymap.set("n", "", require("smart-splits").resize_right) --- moving between splits -vim.keymap.set("n", "", require("smart-splits").move_cursor_left) -vim.keymap.set("n", "", require("smart-splits").move_cursor_down) -vim.keymap.set("n", "", require("smart-splits").move_cursor_up) -vim.keymap.set("n", "", require("smart-splits").move_cursor_right) -vim.keymap.set("n", "", require("smart-splits").move_cursor_previous) --- swapping buffers between windows -vim.keymap.set("n", "h", require("smart-splits").swap_buf_left) -vim.keymap.set("n", "j", require("smart-splits").swap_buf_down) -vim.keymap.set("n", "k", require("smart-splits").swap_buf_up) -vim.keymap.set("n", "l", require("smart-splits").swap_buf_right) +-- Resizing splits +local resize_splits = { + { + "", + function() + smartsplits.resize_left() + end, + "Resize split left", + }, + { + "", + function() + smartsplits.resize_down() + end, + "Resize split down", + }, + { + "", + function() + smartsplits.resize_up() + end, + "Resize split up", + }, + { + "", + function() + smartsplits.resize_right() + end, + "Resize split right", + }, +} --- resizing splits --- these keymaps will also accept a range, --- for example `10` will `resize_left` by `(10 * config.default_amount)` -vim.keymap.set("t", "", require("smart-splits").resize_left) -vim.keymap.set("t", "", require("smart-splits").resize_down) -vim.keymap.set("t", "", require("smart-splits").resize_up) -vim.keymap.set("t", "", require("smart-splits").resize_right) --- moving between splits -vim.keymap.set("t", "", require("smart-splits").move_cursor_left) -vim.keymap.set("t", "", require("smart-splits").move_cursor_down) -vim.keymap.set("t", "", require("smart-splits").move_cursor_up) -vim.keymap.set("t", "", require("smart-splits").move_cursor_right) -vim.keymap.set("t", "", require("smart-splits").move_cursor_previous) --- swapping buffers between windows -vim.keymap.set("t", "h", require("smart-splits").swap_buf_left) -vim.keymap.set("t", "j", require("smart-splits").swap_buf_down) -vim.keymap.set("t", "k", require("smart-splits").swap_buf_up) -vim.keymap.set("t", "l", require("smart-splits").swap_buf_right) +for _, map in ipairs(resize_splits) do + add_keymap(map[1], map[2], map[3], all_modes) +end + +-- Moving between splits +local move_splits = { + { + "", + function() + smartsplits.move_cursor_left() + end, + "Move cursor left", + }, + { + "", + function() + smartsplits.move_cursor_down() + end, + "Move cursor down", + }, + { + "", + function() + smartsplits.move_cursor_up() + end, + "Move cursor up", + }, + { + "", + function() + smartsplits.move_cursor_right() + end, + "Move cursor right", + }, + { + "", + function() + smartsplits.move_cursor_previous() + end, + "Move cursor to previous split", + }, +} + +for _, map in ipairs(move_splits) do + add_keymap(map[1], map[2], map[3], all_modes) +end + +-- Swapping buffers between windows +local swap_buffers = { + { + "", + function() + smartsplits.swap_buf_left() + end, + "Swap buffer left", + }, + { + "", + function() + smartsplits.swap_buf_down() + end, + "Swap buffer down", + }, + { + "", + function() + smartsplits.swap_buf_up() + end, + "Swap buffer up", + }, + { + "", + function() + smartsplits.swap_buf_right() + end, + "Swap buffer right", + }, +} + +for _, map in ipairs(swap_buffers) do + add_keymap(map[1], map[2], map[3], all_modes) +end