♻️ refactor(keymaps): refactor the keymaps definition
Refactor the which-key keymapping configuration to be more efficient and readable
This commit is contained in:
+150
-74
@@ -3,105 +3,181 @@
|
|||||||
-- ╰─────────────────────────────────────────────────────────╯
|
-- ╰─────────────────────────────────────────────────────────╯
|
||||||
-- Initialize which-key
|
-- Initialize which-key
|
||||||
local wk = require("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("<leader>gt", function()
|
||||||
|
rootiest.toggle_lazygit_term()
|
||||||
|
end, "LazyGit Terminal")
|
||||||
|
add_keymap("yo", function()
|
||||||
|
rootiest.yank_line()
|
||||||
|
end, "Yank Line-text")
|
||||||
|
add_keymap("<leader>uH", function()
|
||||||
|
rootiest.toggle_hardmode()
|
||||||
|
end, "Toggle Hardmode")
|
||||||
|
add_keymap("<leader>Y", "<cmd>%y<cr>", "Yank buffer contents")
|
||||||
|
add_keymap("|", "<cmd>Neotree reveal<cr>", "Neotree reveal")
|
||||||
|
|
||||||
|
-- Group Keybinds
|
||||||
wk.add({
|
wk.add({
|
||||||
{ -- Open LazyGit in terminal
|
|
||||||
"<leader>gt",
|
|
||||||
rhs = function()
|
|
||||||
require("config.rootiest").toggle_lazygit_term()
|
|
||||||
end,
|
|
||||||
desc = "LazyGit Terminal",
|
|
||||||
},
|
|
||||||
-- Icon Picker group
|
|
||||||
{
|
{
|
||||||
mode = "n",
|
|
||||||
lhs = "<leader>I",
|
lhs = "<leader>I",
|
||||||
group = "IconPicker",
|
group = "IconPicker",
|
||||||
icon = { icon = "", color = "orange" },
|
icon = { icon = "", color = "orange" },
|
||||||
},
|
},
|
||||||
-- Gists group
|
|
||||||
{
|
{
|
||||||
mode = "n",
|
|
||||||
lhs = "<leader>gn",
|
lhs = "<leader>gn",
|
||||||
group = "Gists",
|
group = "Gists",
|
||||||
icon = { icon = "", color = "orange" },
|
icon = { icon = "", color = "orange" },
|
||||||
},
|
},
|
||||||
{ -- Lazy group
|
{
|
||||||
"<leader>l",
|
lhs = "<leader>l",
|
||||||
group = "Lazy",
|
group = "Lazy",
|
||||||
},
|
},
|
||||||
{ -- LazyVim
|
{
|
||||||
"<leader>lv",
|
"<leader>lv",
|
||||||
"<cmd>Lazy<cr>",
|
"<cmd>Lazy<cr>",
|
||||||
desc = "LazyVim",
|
desc = "LazyVim",
|
||||||
},
|
},
|
||||||
{ -- LazyExtras
|
{
|
||||||
"<leader>lx",
|
"<leader>lx",
|
||||||
"<cmd>LazyExtras<cr>",
|
"<cmd>LazyExtras<cr>",
|
||||||
desc = "LazyExtras",
|
desc = "LazyExtras",
|
||||||
},
|
},
|
||||||
{ -- MiniMap
|
{
|
||||||
"<leader>m",
|
lhs = "<leader>m",
|
||||||
group = "MiniMap",
|
group = "MiniMap",
|
||||||
icon = { icon = "", color = "yellow" },
|
icon = { icon = "", color = "yellow" },
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"yo",
|
|
||||||
rhs = function()
|
|
||||||
require("config.rootiest").yank_line()
|
|
||||||
end,
|
|
||||||
desc = "Yank Line-text",
|
|
||||||
},
|
|
||||||
{ -- Toggle Hardmode with Hints
|
|
||||||
"<leader>uH",
|
|
||||||
rhs = function()
|
|
||||||
require("config.rootiest").toggle_hardmode()
|
|
||||||
end,
|
|
||||||
desc = "Toggle Hardmode",
|
|
||||||
},
|
|
||||||
{ "<leader>u,", group = "Font" },
|
{ "<leader>u,", group = "Font" },
|
||||||
{ -- Yank buffer contents
|
|
||||||
"<leader>Y",
|
|
||||||
"<cmd>%y<cr>",
|
|
||||||
desc = "Yank buffer contents",
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━ smart-splits ━━━━━━━━━━━━━━━━━━━━━━━━━
|
-- Resizing splits
|
||||||
-- recommended mappings
|
local resize_splits = {
|
||||||
-- resizing splits
|
{
|
||||||
-- these keymaps will also accept a range,
|
"<A-h>",
|
||||||
-- for example `10<A-h>` will `resize_left` by `(10 * config.default_amount)`
|
function()
|
||||||
vim.keymap.set("n", "<A-h>", require("smart-splits").resize_left)
|
smartsplits.resize_left()
|
||||||
vim.keymap.set("n", "<A-j>", require("smart-splits").resize_down)
|
end,
|
||||||
vim.keymap.set("n", "<A-k>", require("smart-splits").resize_up)
|
"Resize split left",
|
||||||
vim.keymap.set("n", "<A-l>", require("smart-splits").resize_right)
|
},
|
||||||
-- moving between splits
|
{
|
||||||
vim.keymap.set("n", "<C-S-h>", require("smart-splits").move_cursor_left)
|
"<A-j>",
|
||||||
vim.keymap.set("n", "<C-S-j>", require("smart-splits").move_cursor_down)
|
function()
|
||||||
vim.keymap.set("n", "<C-S-k>", require("smart-splits").move_cursor_up)
|
smartsplits.resize_down()
|
||||||
vim.keymap.set("n", "<C-S-l>", require("smart-splits").move_cursor_right)
|
end,
|
||||||
vim.keymap.set("n", "<C-\\>", require("smart-splits").move_cursor_previous)
|
"Resize split down",
|
||||||
-- swapping buffers between windows
|
},
|
||||||
vim.keymap.set("n", "<leader><leader>h", require("smart-splits").swap_buf_left)
|
{
|
||||||
vim.keymap.set("n", "<leader><leader>j", require("smart-splits").swap_buf_down)
|
"<A-k>",
|
||||||
vim.keymap.set("n", "<leader><leader>k", require("smart-splits").swap_buf_up)
|
function()
|
||||||
vim.keymap.set("n", "<leader><leader>l", require("smart-splits").swap_buf_right)
|
smartsplits.resize_up()
|
||||||
|
end,
|
||||||
|
"Resize split up",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"<A-l>",
|
||||||
|
function()
|
||||||
|
smartsplits.resize_right()
|
||||||
|
end,
|
||||||
|
"Resize split right",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
-- resizing splits
|
for _, map in ipairs(resize_splits) do
|
||||||
-- these keymaps will also accept a range,
|
add_keymap(map[1], map[2], map[3], all_modes)
|
||||||
-- for example `10<A-h>` will `resize_left` by `(10 * config.default_amount)`
|
end
|
||||||
vim.keymap.set("t", "<A-h>", require("smart-splits").resize_left)
|
|
||||||
vim.keymap.set("t", "<A-j>", require("smart-splits").resize_down)
|
-- Moving between splits
|
||||||
vim.keymap.set("t", "<A-k>", require("smart-splits").resize_up)
|
local move_splits = {
|
||||||
vim.keymap.set("t", "<A-l>", require("smart-splits").resize_right)
|
{
|
||||||
-- moving between splits
|
"<C-S-h>",
|
||||||
vim.keymap.set("t", "<C-S-h>", require("smart-splits").move_cursor_left)
|
function()
|
||||||
vim.keymap.set("t", "<C-S-j>", require("smart-splits").move_cursor_down)
|
smartsplits.move_cursor_left()
|
||||||
vim.keymap.set("t", "<C-S-k>", require("smart-splits").move_cursor_up)
|
end,
|
||||||
vim.keymap.set("t", "<C-S-l>", require("smart-splits").move_cursor_right)
|
"Move cursor left",
|
||||||
vim.keymap.set("t", "<C-\\>", require("smart-splits").move_cursor_previous)
|
},
|
||||||
-- swapping buffers between windows
|
{
|
||||||
vim.keymap.set("t", "<leader><leader>h", require("smart-splits").swap_buf_left)
|
"<C-S-j>",
|
||||||
vim.keymap.set("t", "<leader><leader>j", require("smart-splits").swap_buf_down)
|
function()
|
||||||
vim.keymap.set("t", "<leader><leader>k", require("smart-splits").swap_buf_up)
|
smartsplits.move_cursor_down()
|
||||||
vim.keymap.set("t", "<leader><leader>l", require("smart-splits").swap_buf_right)
|
end,
|
||||||
|
"Move cursor down",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"<C-S-k>",
|
||||||
|
function()
|
||||||
|
smartsplits.move_cursor_up()
|
||||||
|
end,
|
||||||
|
"Move cursor up",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"<C-S-l>",
|
||||||
|
function()
|
||||||
|
smartsplits.move_cursor_right()
|
||||||
|
end,
|
||||||
|
"Move cursor right",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"<C-\\>",
|
||||||
|
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 = {
|
||||||
|
{
|
||||||
|
"<A-S-h>",
|
||||||
|
function()
|
||||||
|
smartsplits.swap_buf_left()
|
||||||
|
end,
|
||||||
|
"Swap buffer left",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"<A-S-j>",
|
||||||
|
function()
|
||||||
|
smartsplits.swap_buf_down()
|
||||||
|
end,
|
||||||
|
"Swap buffer down",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"<A-S-k>",
|
||||||
|
function()
|
||||||
|
smartsplits.swap_buf_up()
|
||||||
|
end,
|
||||||
|
"Swap buffer up",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"<A-S-l>",
|
||||||
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user