refactor: simplify

This commit is contained in:
2026-09-03 20:27:45 +02:00
parent 71434f947b
commit ddd0c73341
8 changed files with 147 additions and 204 deletions
+70 -79
View File
@@ -13,105 +13,96 @@ Config.leader_group_clues = {
{ mode = "x", keys = "<Leader>l", desc = "+Language" },
}
-- Helpers =====================================================================
local function map(mode, lhs, rhs, desc, plugin)
local final_rhs = plugin and function()
if Config["setup_" .. plugin] then Config["setup_" .. plugin]() end
rhs()
end or rhs
vim.keymap.set(mode, lhs, final_rhs, { desc = desc })
-- Keymap Helpers =============================================================
local function map(mode, lhs, rhs, desc)
vim.keymap.set(mode, lhs, rhs, { desc = desc, silent = true })
end
local nmap = function(lhs, rhs, desc, plugin) map("n", lhs, rhs, desc, plugin) end
local tmap = function(lhs, rhs, desc, plugin) map("t", lhs, rhs, desc, plugin) end
local nmap_leader = function(suffix, rhs, desc, plugin) map("n", "<Leader>" .. suffix, rhs, desc, plugin) end
local xmap_leader = function(suffix, rhs, desc, plugin) map("x", "<Leader>" .. suffix, rhs, desc, plugin) end
local function leader(suffix, rhs, desc, mode)
map(mode or "n", "<Leader>" .. suffix, rhs, desc)
end
-- Buffers =====================================================================
nmap_leader("bd", function() pcall(vim.cmd, "bdelete") end, "Delete")
nmap_leader("bD", function() pcall(vim.cmd, "bdelete!") end, "Delete!")
nmap_leader("bw", function() pcall(vim.cmd, "bwipeout") end, "Wipeout")
nmap_leader("bW", function() pcall(vim.cmd, "bwipeout!") end, "Wipeout!")
nmap_leader("bo", function()
leader("bd", "<cmd>bdelete<CR>", "Delete")
leader("bD", "<cmd>bdelete!<CR>", "Delete!")
leader("bw", "<cmd>bwipeout<CR>", "Wipeout")
leader("bW", "<cmd>bwipeout!<CR>", "Wipeout!")
leader("bo", function()
local visible = vim.iter(vim.api.nvim_list_wins()):map(vim.api.nvim_win_get_buf):totable()
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
if not vim.list_contains(visible, buf) then
pcall(vim.api.nvim_buf_delete, buf, { force = false })
end
end
end, "Close all invisible buffers")
vim.iter(vim.api.nvim_list_bufs())
:filter(function(buf) return not vim.list_contains(visible, buf) end)
:each(function(buf) pcall(vim.api.nvim_buf_delete, buf, { force = false }) end)
end, "Close invisible buffers")
-- Debug =======================================================================
nmap_leader("db", function() require("dap").toggle_breakpoint() end, "Toggle Breakpoint", "dap")
nmap_leader("dl", function() require("dap").set_breakpoint(nil, nil, vim.fn.input("Log point message: ")) end,
"log point", "dap")
nmap_leader("dc", function() require("dap").continue() end, "Run/Continue", "dap")
nmap_leader("dC", function() require("dap").run_to_cursor() end, "Run to Cursor", "dap")
nmap_leader("de", function() require("dap.ui.widgets").hover() end, "Inspect", "dap")
nmap_leader("dr", function() require("dap").repl.open() end, "Open repl", "dap")
nmap_leader("dt", function() require("dap").terminate() end, "Terminate", "dap")
leader("db", function() require("dap").toggle_breakpoint() end, "Toggle Breakpoint")
leader("dl", function() require("dap").set_breakpoint(nil, nil, vim.fn.input("Log point: ")) end, "Log point")
leader("dc", function() require("dap").continue() end, "Run/Continue")
leader("dC", function() require("dap").run_to_cursor() end, "Run to Cursor")
leader("de", function() require("dap.ui.widgets").hover() end, "Inspect")
leader("dr", function() require("dap").repl.open() end, "Open REPL")
leader("dt", function() require("dap").terminate() end, "Terminate")
-- Explore =====================================================================
nmap_leader("ed", function() MiniFiles.open() end, "Directory")
nmap_leader("ef",
function() MiniFiles.open(vim.uv.fs_stat(vim.api.nvim_buf_get_name(0)) and vim.api.nvim_buf_get_name(0) or nil) end,
"File directory")
leader("ed", function() MiniFiles.open() end, "Directory")
leader("ef", function()
local file = vim.api.nvim_buf_get_name(0)
MiniFiles.open(vim.uv.fs_stat(file) and file or nil)
end, "File directory")
-- Find ========================================================================
nmap_leader("fb", function() MiniPick.builtin.buffers() end, "Buffers")
nmap_leader("fc", function() MiniExtra.pickers.git_commits() end, "Commits (all)")
nmap_leader("fC", function() MiniExtra.pickers.git_commits({ path = "%" }) end, "Commits (buf)")
nmap_leader("fd", function() MiniExtra.pickers.diagnostic({ scope = "all" }) end, "Diagnostic workspace")
nmap_leader("fD", function() MiniExtra.pickers.diagnostic({ scope = "current" }) end, "Diagnostic buffer")
nmap_leader("ff", function() MiniPick.builtin.files() end, "Files")
nmap_leader("fg", function() MiniPick.builtin.grep_live() end, "Grep live")
nmap_leader("fG", function() MiniPick.builtin.grep({ pattern = vim.fn.expand("<cword>") }) end, "Grep current word")
nmap_leader("fh", function() MiniPick.builtin.help() end, "Help tags")
nmap_leader("fl", function() MiniPick.builtin.buf_lines({ scope = "all" }) end, "Lines (all)")
nmap_leader("fL", function() MiniPick.builtin.buf_lines({ scope = "current" }) end, "Lines (buf)")
nmap_leader("fr", function() MiniPick.builtin.resume() end, "Resume")
nmap_leader("fs", function() MiniExtra.pickers.lsp({ scope = "workspace_symbol_live" }) end, "Symbols workspace (live)")
nmap_leader("fS", function() MiniExtra.pickers.lsp({ scope = "document_symbol" }) end, "Symbols document")
nmap_leader("f:", function() MiniExtra.pickers.history({ scope = ":" }) end, '":" history')
nmap_leader("f;", function() MiniExtra.pickers.history({ scope = ":" }) end, "Command history")
leader("fb", function() MiniPick.builtin.buffers() end, "Buffers")
leader("fc", function() MiniExtra.pickers.git_commits() end, "Commits (all)")
leader("fC", function() MiniExtra.pickers.git_commits({ path = "%" }) end, "Commits (buf)")
leader("fd", function() MiniExtra.pickers.diagnostic({ scope = "all" }) end, "Diagnostic workspace")
leader("fD", function() MiniExtra.pickers.diagnostic({ scope = "current" }) end, "Diagnostic buffer")
leader("ff", function() MiniPick.builtin.files() end, "Files")
leader("fg", function() MiniPick.builtin.grep_live() end, "Grep live")
leader("fG", function() MiniPick.builtin.grep({ pattern = vim.fn.expand("<cword>") }) end, "Grep word")
leader("fh", function() MiniPick.builtin.help() end, "Help tags")
leader("fl", function() MiniPick.builtin.buf_lines({ scope = "all" }) end, "Lines (all)")
leader("fL", function() MiniPick.builtin.buf_lines({ scope = "current" }) end, "Lines (buf)")
leader("fr", function() MiniPick.builtin.resume() end, "Resume")
leader("fs", function() MiniExtra.pickers.lsp({ scope = "workspace_symbol_live" }) end, "Symbols workspace")
leader("fS", function() MiniExtra.pickers.lsp({ scope = "document_symbol" }) end, "Symbols document")
leader("f:", function() MiniExtra.pickers.history({ scope = ":" }) end, "Command history")
-- Git =========================================================================
nmap_leader("go", function() MiniDiff.toggle_overlay() end, "Toggle overlay")
nmap_leader("gs", function() MiniGit.show_at_cursor() end, "Show at cursor")
xmap_leader("gs", function() MiniGit.show_at_cursor() end, "Show at selection")
leader("go", function() MiniDiff.toggle_overlay() end, "Toggle overlay")
leader("gs", function() MiniGit.show_at_cursor() end, "Show at cursor")
leader("gs", function() MiniGit.show_at_cursor() end, "Show selection", "x")
-- Language ====================================================================
nmap_leader("la", function() vim.lsp.buf.code_action() end, "Actions")
nmap_leader("ld", function() vim.diagnostic.open_float() end, "Diagnostic popup")
nmap_leader("lf", function() require("conform").format({ async = true }) end, "Format")
nmap_leader("li", function() vim.lsp.buf.implementation() end, "Implementation")
nmap_leader("lh", function() vim.lsp.buf.hover() end, "Hover")
nmap_leader("ll", function() vim.lsp.codelens.run() end, "Lens")
nmap_leader("lr", function() vim.lsp.buf.rename() end, "Rename")
nmap_leader("lR", function() vim.lsp.buf.references() end, "References")
nmap_leader("ls", function() vim.lsp.buf.definition() end, "Source definition")
nmap_leader("lt", function() vim.lsp.buf.type_definition() end, "Type definition")
xmap_leader("lf", function() require("conform").format({ async = true }) end, "Format selection")
leader("la", vim.lsp.buf.code_action, "Actions")
leader("ld", vim.diagnostic.open_float, "Diagnostic popup")
leader("lf", function() require("conform").format({ async = true }) end, "Format")
leader("lf", function() require("conform").format({ async = true }) end, "Format selection", "x")
leader("li", vim.lsp.buf.implementation, "Implementation")
leader("lh", vim.lsp.buf.hover, "Hover")
leader("ll", vim.lsp.codelens.run, "Lens")
leader("lr", vim.lsp.buf.rename, "Rename")
leader("lR", vim.lsp.buf.references, "References")
leader("ls", vim.lsp.buf.definition, "Source definition")
leader("lt", vim.lsp.buf.type_definition, "Type definition")
-- Run =========================================================================
nmap_leader("rj", function() require("just").pick_just_task() end, "Run Just Task")
nmap_leader("rh", function() require("kulala").run() end, "Send HTTP request", "kulala")
leader("rj", function() require("just").pick_just_task() end, "Run Just Task")
leader("rh", function() require("kulala").run() end, "Send HTTP request")
-- Session =====================================================================
nmap_leader("sd", function() MiniSessions.select("delete") end, "Delete")
nmap_leader("sn", function() vim.ui.input({ prompt = "Session name: " }, MiniSessions.write) end, "New")
nmap_leader("sr", function() MiniSessions.select("read") end, "Read")
nmap_leader("sR", function() MiniSessions.restart() end, "Restart")
nmap_leader("sw", function() MiniSessions.write() end, "Write current")
leader("sd", function() MiniSessions.select("delete") end, "Delete")
leader("sn", function() vim.ui.input({ prompt = "Session name: " }, MiniSessions.write) end, "New")
leader("sr", function() MiniSessions.select("read") end, "Read")
leader("sR", function() MiniSessions.restart() end, "Restart")
leader("sw", function() MiniSessions.write() end, "Write current")
-- Terminal ====================================================================
nmap_leader("tT", function() vim.cmd("horizontal term") end, "Terminal (horizontal)")
nmap_leader("tt", function() vim.cmd("vertical term") end, "Terminal (vertical)")
nmap_leader("tc", function() vim.cmd("vertical term claude") end, "Claude")
nmap_leader("tg", function() require("terminal").open_terminal_app("lazygit") end, "LazyGit")
nmap_leader("ts", function() require("terminal").open_terminal_app("lazysql") end, "LazySQL")
leader("tT", "<cmd>horizontal term<CR>", "Terminal (horizontal)")
leader("tt", "<cmd>vertical term<CR>", "Terminal (vertical)")
leader("tc", "<cmd>vertical term claude<CR>", "Claude")
leader("tg", function() require("terminal").open_terminal_app("lazygit") end, "LazyGit")
leader("ts", function() require("terminal").open_terminal_app("lazysql") end, "LazySQL")
-- Overwrites ==================================================================
nmap("<Esc>", function() vim.cmd("nohlsearch") end, "Clear search highlights")
tmap("<C-w>", "<C-\\><C-n><C-w>", "Terminal window navigation")
map("n", "<Esc>", "<cmd>nohlsearch<CR>", "Clear highlights")
map("t", "<C-w>", "<C-\\><C-n><C-w>", "Terminal window navigation")