refactor: centralize all keybind definitions into data module

This commit is contained in:
2024-08-29 14:25:29 -04:00
parent ac435892e9
commit 8f65f878a7
2 changed files with 261 additions and 184 deletions
+31 -183
View File
@@ -1,197 +1,45 @@
-- ╭─────────────────────────────────────────────────────────╮
-- │ Keybinds │
-- ╰─────────────────────────────────────────────────────────╯
-- Initialize which-key
local wk = require("which-key")
local rootiest = require("config.rootiest")
local smartsplits = require("smart-splits")
-- All keybinds are defined in lua/data/keys.lua
-- This allows both plugin and general keybinds to
-- be defined in a single central location
-- Load data module
local data = require("data")
local all_modes = { "n", "i", "v", "x", "s", "o", "c", "t" }
-- Add keymapper function
local add_keymap = data.func.add_keymap
local add_keymap = require("data").func.add_keymap
-- ━━━━━━━━━━━━━━━━━━━━━━━━━━ General Keybinds ━━━━━━━━━━━━━━━━━━━━━━━
-- 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("<C-a>", "<cmd>norm ggVG<cr>", "Select all")
add_keymap("|", "<cmd>Neotree reveal toggle<cr>", "Neotree reveal")
add_keymap(
"<leader>Ca",
":<C-U>lua require('utils.rootiest').code_action_on_selection()<CR>",
"Code Action on Selection",
"x"
)
-- Exit Neovim
add_keymap({
lhs = "<leader>Cq",
rhs = function()
data.func.exit()
end,
desc = "Exit Neovim",
})
-- Group Keybinds
wk.add({
{
lhs = "<leader>I",
group = "IconPicker",
icon = { icon = "󰥸", color = "orange" },
},
{
lhs = "<leader>gn",
group = "Gists",
icon = { icon = "", color = "orange" },
},
{
lhs = "<leader>l",
group = "Lazy",
},
{
"<leader>lv",
"<cmd>Lazy<cr>",
desc = "LazyVim",
},
{
"<leader>lx",
"<cmd>LazyExtras<cr>",
desc = "LazyExtras",
},
{
lhs = "<leader>m",
group = "MiniMap",
icon = { icon = "", color = "yellow" },
},
{ "<leader>u,", group = "Font" },
})
-- Resizing splits
local resize_splits = {
{
"<A-h>",
function()
smartsplits.resize_left()
end,
"Resize split left",
},
{
"<A-j>",
function()
smartsplits.resize_down()
end,
"Resize split down",
},
{
"<A-k>",
function()
smartsplits.resize_up()
end,
"Resize split up",
},
{
"<A-l>",
function()
smartsplits.resize_right()
end,
"Resize split right",
},
{
"<A-r>",
function()
smartsplits.start_resize_mode()
end,
"Resize split to previous size",
},
}
for _, map in ipairs(resize_splits) do
add_keymap(map[1], map[2], map[3], all_modes)
-- Add keymaps for miscellaneous keybinds
for _, item in ipairs(data.keys.misc) do
add_keymap(item)
end
-- Moving between splits
local move_splits = {
{
"<C-S-h>",
function()
smartsplits.move_cursor_left()
end,
"Move cursor left",
},
{
"<C-S-j>",
function()
smartsplits.move_cursor_down()
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",
},
}
-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━ Group Keybinds ━━━━━━━━━━━━━━━━━━━━━━━━
for _, map in ipairs(move_splits) do
add_keymap(map[1], map[2], map[3], all_modes)
-- Add keymaps for menu groups
for _, item in ipairs(data.keys.groups) do
add_keymap(item)
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",
},
}
-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━ Resizing splits ━━━━━━━━━━━━━━━━━━━━━━━━━━━
for _, map in ipairs(swap_buffers) do
add_keymap(map[1], map[2], map[3], all_modes)
for _, map in ipairs(data.keys.splits.resize) do
add_keymap(map[1], map[2], map[3], data.types.all_modes)
end
-- ━━━━━━━━━━━━━━━━━━━━━━━━ Moving between splits ━━━━━━━━━━━━━━━━━━━━━━━━
for _, map in ipairs(data.keys.splits.move) do
add_keymap(map[1], map[2], map[3], data.types.all_modes)
end
-- ━━━━━━━━━━━━━━━━━━ Swapping buffers between windows ━━━━━━━━━━━━━━━
for _, map in ipairs(data.keys.splits.swap) do
add_keymap(map[1], map[2], map[3], data.types.all_modes)
end
+230 -1
View File
@@ -4,6 +4,9 @@
local M = {}
-- Load utils
local rootiest = require("config.rootiest")
M.alternate = {
{ -- Toggle Alternate
"<leader>a",
@@ -220,6 +223,39 @@ M.gist = {
},
}
M.groups = {
-- Icon picker
{
lhs = "<leader>I",
group = "IconPicker",
icon = { icon = "󰥸", color = "orange" },
},
-- Gists menu
{
lhs = "<leader>gn",
group = "Gists",
icon = { icon = "", color = "orange" },
},
-- Lazy menu
{
lhs = "<leader>l",
group = "Lazy",
icon = { icon = "󰒲", color = "red" },
},
-- MiniMap menu
{
lhs = "<leader>n",
group = "MiniMap",
icon = { icon = "", color = "green" },
},
-- Code action menu
{
lhs = "<leader>C",
group = "CodeActions",
icon = { icon = "", color = "yellow" },
},
}
M.gx = {
{ -- Open URL/Link
"gx",
@@ -256,6 +292,83 @@ M.lazygit = {
},
}
M.misc = {
-- LazyGit
{
lhs = "<leader>gt",
rhs = function()
rootiest.toggle_lazygit_term()
end,
desc = "LazyGit Terminal",
},
-- Yank line (without whitespace)
{
lhs = "yo",
rhs = function()
rootiest.yank_line()
end,
desc = "Yank Line-text",
},
-- Hardmode
{
lhs = "<leader>uH",
rhs = function()
rootiest.toggle_hardmode()
end,
desc = "Toggle Hardmode",
},
-- Yank buffer
{
lhs = "<leader>Y",
rhs = "<cmd>%y<cr>",
desc = "Yank buffer contents",
},
-- Select all
{
lhs = "<C-a>",
rhs = "<cmd>norm ggVG<cr>",
desc = "Select all",
},
-- Neotree
{
lhs = "|",
rhs = "<cmd>Neotree reveal toggle<cr>",
desc = "Neotree toggle",
},
-- Code action on selection
{
lhs = "<leader>Ca",
rhs = ":<C-U>lua require('utils.rootiest').code_action_on_selection()<CR>",
desc = "Code Action on Selection",
mode = "x",
},
-- Exit Neovim
{
lhs = "<leader>Q",
rhs = "<cmd>lua require('data').func.exit()<cr>",
desc = "Exit Neovim",
},
-- LazyVim
{
lhs = "<leader>lv",
rhs = "<cmd>Lazy<cr>",
desc = "LazyVim",
},
-- LazyExtras
{
lhs = "<leader>lx",
rhs = "<cmd>LazyExtras<cr>",
desc = "LazyExtras",
},
-- De-map 's' to avoid conflicts with mini.surround
{
lhs = "s",
rhs = "<Nop>",
desc = "Nos",
mode = { "n", "x" },
},
}
M.nekifoch = {
{ -- List Fonts
"<leader>u,l",
@@ -294,7 +407,7 @@ M.precog = {
}
M.qalc = {
{
{ -- Open Qalc
"<leader>qc",
"<cmd>Qalc<cr>",
desc = "Qalc",
@@ -316,6 +429,113 @@ M.splitjoin = {
toggle = "gJ",
}
M.splits = {
resize = {
{
"<A-h>",
function()
require("smart-splits").resize_left()
end,
"Resize split left",
},
{
"<A-j>",
function()
require("smart-splits").resize_down()
end,
"Resize split down",
},
{
"<A-k>",
function()
require("smart-splits").resize_up()
end,
"Resize split up",
},
{
"<A-l>",
function()
require("smart-splits").resize_right()
end,
"Resize split right",
},
{
"<A-r>",
function()
require("smart-splits").start_resize_mode()
end,
"Resize split to previous size",
},
},
move = {
{
"<C-S-h>",
function()
require("smart-splits").move_cursor_left()
end,
"Move cursor left",
},
{
"<C-S-j>",
function()
require("smart-splits").move_cursor_down()
end,
"Move cursor down",
},
{
"<C-S-k>",
function()
require("smart-splits").move_cursor_up()
end,
"Move cursor up",
},
{
"<C-S-l>",
function()
require("smart-splits").move_cursor_right()
end,
"Move cursor right",
},
{
"<C-\\>",
function()
require("smart-splits").move_cursor_previous()
end,
"Move cursor to previous split",
},
},
swap = {
{
"<A-S-h>",
function()
require("smart-splits").swap_buf_left()
end,
"Swap buffer left",
},
{
"<A-S-j>",
function()
require("smart-splits").swap_buf_down()
end,
"Swap buffer down",
},
{
"<A-S-k>",
function()
require("smart-splits").swap_buf_up()
end,
"Swap buffer up",
},
{
"<A-S-l>",
function()
require("smart-splits").swap_buf_right()
end,
"Swap buffer right",
},
},
}
M.substitute = {
{ -- Substitute operator in normal mode
"x",
@@ -356,6 +576,15 @@ M.substitute = {
},
}
M.surround = {
{ -- De-map 's' to prevent conflicts
"s",
"<Nop>",
desc = "Nos",
mode = { "n", "x" },
},
}
M.toggleterm = {
{ -- Toggle Terminal
"<c-/>",