♻️ refactor(keymaps): refactor keymaps for performance

Better keymap performance by smarter loading of dependencies and plugins
This commit is contained in:
2024-08-04 03:55:33 -04:00
parent d161476fa8
commit ebb26fe3ee
+34 -40
View File
@@ -4,25 +4,19 @@
-- --------------------------------- Keymaps ----------------------------------- -- --------------------------------- Keymaps -----------------------------------
-- Initialize dependencies
local substitute_loaded, substitute = pcall(require, "substitute")
local codesnap_loaded = pcall(require, "codesnap")
local icon_picker_loaded = pcall(require, "icon-picker")
local gist_loaded = pcall(require, "gist")
local rootiest = require("config.rootiest")
-- Initialize which-key -- Initialize which-key
local wk = require("which-key") local wk = require("which-key")
wk.add({ wk.add({
{ { -- Toggle Terminal
mode = "n",
"<c-/>", "<c-/>",
":ToggleTerm<cr>", ":ToggleTerm<cr>",
desc = "Toggle Terminal", desc = "Toggle Terminal",
}, },
{ { -- Open LazyGit in terminal
"<leader>gt", "<leader>gt",
rhs = function() rhs = function()
rootiest.toggle_lazygit_term() require("config.rootiest").toggle_lazygit_term()
end, end,
desc = "LazyGit Terminal", desc = "LazyGit Terminal",
}, },
@@ -33,7 +27,7 @@ wk.add({
group = "IconPicker", group = "IconPicker",
icon = { icon = "󰥸", color = "orange" }, icon = { icon = "󰥸", color = "orange" },
cond = function() cond = function()
return icon_picker_loaded return pcall(require, "icon-picker")
end, end,
}, },
-- Pick Icon -- Pick Icon
@@ -44,7 +38,7 @@ wk.add({
desc = "Pick Icon", desc = "Pick Icon",
group = "IconPicker", group = "IconPicker",
cond = function() cond = function()
return icon_picker_loaded return pcall(require, "icon-picker")
end, end,
}, },
-- Yank Icon -- Yank Icon
@@ -55,7 +49,7 @@ wk.add({
desc = "Yank Icon", desc = "Yank Icon",
group = "IconPicker", group = "IconPicker",
cond = function() cond = function()
return icon_picker_loaded return pcall(require, "icon-picker")
end, end,
}, },
-- Insert Icon in insert mode -- Insert Icon in insert mode
@@ -66,7 +60,7 @@ wk.add({
desc = "Insert Icon", desc = "Insert Icon",
group = "IconPicker", group = "IconPicker",
cond = function() cond = function()
return icon_picker_loaded return pcall(require, "icon-picker")
end, end,
}, },
-- Gists group -- Gists group
@@ -76,7 +70,7 @@ wk.add({
group = "Gists", group = "Gists",
icon = { icon = "", color = "orange" }, icon = { icon = "", color = "orange" },
cond = function() cond = function()
return gist_loaded return pcall(require, "gist")
end, end,
}, },
-- Create Gist -- Create Gist
@@ -86,7 +80,7 @@ wk.add({
rhs = "<cmd>GistCreate<cr>", rhs = "<cmd>GistCreate<cr>",
desc = "Create Gist", desc = "Create Gist",
cond = function() cond = function()
return gist_loaded return pcall(require, "gist")
end, end,
}, },
-- Find Gists -- Find Gists
@@ -96,24 +90,24 @@ wk.add({
rhs = "<cmd>GistList<cr>", rhs = "<cmd>GistList<cr>",
desc = "Find Gists", desc = "Find Gists",
cond = function() cond = function()
return gist_loaded return pcall(require, "gist")
end, end,
}, },
{ { -- Lazy group
"<leader>l", "<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", "<leader>m",
group = "MiniMap", group = "MiniMap",
icon = { icon = "", color = "yellow" }, icon = { icon = "", color = "yellow" },
@@ -125,7 +119,7 @@ wk.add({
rhs = "<cmd>CodeSnap<cr>", rhs = "<cmd>CodeSnap<cr>",
desc = "Save selected code snapshot into clipboard", desc = "Save selected code snapshot into clipboard",
cond = function() cond = function()
return codesnap_loaded return pcall(require, "codesnap")
end, end,
}, },
-- Save selected code snapshot in ~/Pictures -- Save selected code snapshot in ~/Pictures
@@ -135,7 +129,7 @@ wk.add({
rhs = "<cmd>CodeSnapSave<cr>", rhs = "<cmd>CodeSnapSave<cr>",
desc = "Save selected code snapshot in ~/Pictures", desc = "Save selected code snapshot in ~/Pictures",
cond = function() cond = function()
return codesnap_loaded return pcall(require, "codesnap")
end, end,
}, },
-- Highlight and snapshot selected code into clipboard -- Highlight and snapshot selected code into clipboard
@@ -145,7 +139,7 @@ wk.add({
rhs = "<cmd>CodeSnapHighlight<cr>", rhs = "<cmd>CodeSnapHighlight<cr>",
desc = "Highlight and snapshot selected code into clipboard", desc = "Highlight and snapshot selected code into clipboard",
cond = function() cond = function()
return codesnap_loaded return pcall(require, "codesnap")
end, end,
}, },
-- Save ASCII code snapshot into clipboard -- Save ASCII code snapshot into clipboard
@@ -155,7 +149,7 @@ wk.add({
rhs = "<cmd>CodeSnapASCII<cr>", rhs = "<cmd>CodeSnapASCII<cr>",
desc = "Save ASCII code snapshot into clipboard", desc = "Save ASCII code snapshot into clipboard",
cond = function() cond = function()
return codesnap_loaded return pcall(require, "codesnap")
end, end,
}, },
{ {
@@ -184,7 +178,7 @@ wk.add({
end, end,
desc = "KittyNavigateLeft", desc = "KittyNavigateLeft",
cond = function() -- Using Kitty cond = function() -- Using Kitty
return rootiest.using_kitty() return require("config.rootiest").using_kitty()
end, end,
}, },
{ {
@@ -194,7 +188,7 @@ wk.add({
end, end,
desc = "KittyNavigateDown", desc = "KittyNavigateDown",
cond = function() -- Using Kitty cond = function() -- Using Kitty
return rootiest.using_kitty() return require("config.rootiest").using_kitty()
end, end,
}, },
{ {
@@ -204,7 +198,7 @@ wk.add({
end, end,
desc = "KittyNavigateUp", desc = "KittyNavigateUp",
cond = function() -- Using Kitty cond = function() -- Using Kitty
return rootiest.using_kitty() return require("config.rootiest").using_kitty()
end, end,
}, },
{ {
@@ -214,13 +208,13 @@ wk.add({
end, end,
desc = "KittyNavigateRight", desc = "KittyNavigateRight",
cond = function() -- Using Kitty cond = function() -- Using Kitty
return rootiest.using_kitty() return require("config.rootiest").using_kitty()
end, end,
}, },
{ {
"zk", "zk",
rhs = function() rhs = function()
rootiest.toggle_precognition() require("config.rootiest").toggle_precognition()
end, end,
desc = "Toggle Precognition", desc = "Toggle Precognition",
}, },
@@ -255,14 +249,14 @@ wk.add({
{ {
"yo", "yo",
rhs = function() rhs = function()
rootiest.yank_line() require("config.rootiest").yank_line()
end, end,
desc = "Yank Line-text", desc = "Yank Line-text",
}, },
{ -- Toggle Hardmode with Hints { -- Toggle Hardmode with Hints
"<leader>h", "<leader>h",
rhs = function() rhs = function()
rootiest.toggle_hardmode() require("config.rootiest").toggle_hardmode()
end, end,
desc = "Toggle Hardmode", desc = "Toggle Hardmode",
}, },
@@ -278,11 +272,11 @@ wk.add({
mode = "n", mode = "n",
lhs = "x", lhs = "x",
rhs = function() rhs = function()
substitute.operator() require("substitute").operator()
end, end,
desc = "Substitute operator", desc = "Substitute operator",
cond = function() cond = function()
return substitute_loaded return pcall(require, "substitute")
end, end,
}, },
-- Substitute line in normal mode -- Substitute line in normal mode
@@ -290,11 +284,11 @@ wk.add({
mode = "n", mode = "n",
lhs = "xx", lhs = "xx",
rhs = function() rhs = function()
substitute.line() require("substitute").line()
end, end,
desc = "Substitute line", desc = "Substitute line",
cond = function() cond = function()
return substitute_loaded return pcall(require, "substitute")
end, end,
}, },
-- Substitute end of line in normal mode -- Substitute end of line in normal mode
@@ -302,11 +296,11 @@ wk.add({
mode = "n", mode = "n",
lhs = "X", lhs = "X",
rhs = function() rhs = function()
substitute.eol() require("substitute").eol()
end, end,
desc = "Substitute end of line", desc = "Substitute end of line",
cond = function() cond = function()
return substitute_loaded return pcall(require, "substitute")
end, end,
}, },
-- Substitute visual selection in visual mode -- Substitute visual selection in visual mode
@@ -314,11 +308,11 @@ wk.add({
mode = "x", mode = "x",
lhs = "x", lhs = "x",
rhs = function() rhs = function()
substitute.visual() require("substitute").visual()
end, end,
desc = "Substitute visual selection", desc = "Substitute visual selection",
cond = function() cond = function()
return substitute_loaded return pcall(require, "substitute")
end, end,
}, },
{ "<leader>u,", group = "Font" }, { "<leader>u,", group = "Font" },