Files
neovim-config/plugin/20_keymaps.lua
T
2026-08-29 17:02:35 +02:00

130 lines
7.3 KiB
Lua

-- Clues =======================================================================
Config.leader_group_clues = {
{ mode = "n", keys = "<Leader>b", desc = "+Buffer" },
{ mode = "n", keys = "<Leader>d", desc = "+Debug" },
{ mode = "n", keys = "<Leader>e", desc = "+Explore" },
{ mode = "n", keys = "<Leader>f", desc = "+Find" },
{ mode = "n", keys = "<Leader>g", desc = "+Git" },
{ mode = "n", keys = "<Leader>h", desc = "+Http" },
{ mode = "n", keys = "<Leader>l", desc = "+Language" },
{ mode = "n", keys = "<Leader>r", desc = "+Run" },
{ mode = "n", keys = "<Leader>s", desc = "+Session" },
{ mode = "n", keys = "<Leader>t", desc = "+Terminal" },
{ mode = "x", keys = "<Leader>g", desc = "+Git" },
{ mode = "x", keys = "<Leader>l", desc = "+Language" },
}
-- Helpers =====================================================================
local function lazy_wrap(name, action)
return function()
if Config["setup_" .. name] then Config["setup_" .. name]() end
action()
end
end
local nmap = function(lhs, rhs, desc, plugin)
local final_rhs = plugin and lazy_wrap(plugin, rhs) or rhs
vim.keymap.set("n", lhs, final_rhs, { desc = desc })
end
local tmap = function(lhs, rhs, desc, plugin)
local final_rhs = plugin and lazy_wrap(plugin, rhs) or rhs
vim.keymap.set("t", lhs, final_rhs, { desc = desc })
end
local nmap_leader = function(suffix, rhs, desc, plugin)
local final_rhs = plugin and lazy_wrap(plugin, rhs) or rhs
vim.keymap.set("n", "<Leader>" .. suffix, final_rhs, { desc = desc })
end
local xmap_leader = function(suffix, rhs, desc, plugin)
local final_rhs = plugin and lazy_wrap(plugin, rhs) or rhs
vim.keymap.set("x", "<Leader>" .. suffix, final_rhs, { desc = 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()
local current = vim.api.nvim_get_current_buf()
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
if buf ~= current and vim.api.nvim_buf_is_loaded(buf) and vim.bo[buf].buflisted then
pcall(vim.api.nvim_buf_delete, buf, { force = false })
end
end
end, "Close all but current")
-- Debug =======================================================================
nmap_leader("db", function() require("dap").toggle_breakpoint() end, "Toggle Breakpoint", "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("dt", function() require("dap").terminate() end, "Terminate", "dap")
-- 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")
-- 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")
-- 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")
-- HTTP ========================================================================
nmap_leader("hr", function() require("kulala").run() end, "Send HTTP request", "kulala")
-- 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")
-- Run =========================================================================
nmap_leader("r", function() require("just").pick_just_task() end, "Run Just Task")
-- 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")
-- 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("tg", function() require("terminal").open_terminal_app("lazygit") end, "LazyGit")
nmap_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")