local map = vim.keymap.set local silent = { silent = true } -- Visual line navigation for _, mode in ipairs({ "n", "v" }) do map(mode, "j", "gj", silent) map(mode, "k", "gk", silent) end -- Hover: diagnostics on current line if any, else LSP hover map("n", "K", function() local line = vim.api.nvim_win_get_cursor(0)[1] - 1 if #vim.diagnostic.get(0, { lnum = line }) > 0 then vim.diagnostic.open_float() else vim.lsp.buf.hover() end end, { desc = "Hover (diagnostic or LSP)" }) -- LSP map("n", "gf", function() require("conform").format({ lsp_format = "fallback" }) end, { desc = "Format buffer" }) map("n", "gd", vim.lsp.buf.definition) map("n", "gD", vim.lsp.buf.declaration) map("n", "ca", vim.lsp.buf.code_action, { desc = "Code Action" }) map("n", "rn", vim.lsp.buf.rename, { desc = "Rename symbol" }) -- Trouble map("n", "xx", "Trouble diagnostics toggle focus=true", { desc = "Diagnostics (Trouble)" }) map("n", "xX", "Trouble diagnostics toggle filter.buf=0 focus=true", { desc = "Buffer Diagnostics (Trouble)" }) map("n", "xt", "Trouble todo toggle", { desc = "Todo (Trouble)" }) -- Pickers / files map("n", "", "Pick files") map("n", "", "Pick grep_live") map("n", "", "Pick help") map("n", "", "Oil") -- DAP map("n", "duo", function() require("dapui").open() end) map("n", "duc", function() require("dapui").close() end) map("n", "dbp", function() require("dap").toggle_breakpoint() end) map("n", "drc", function() require("dap").run_to_cursor() end) -- Barbar map("n", "H", "BufferPrevious", silent) map("n", "L", "BufferNext", silent) map("n", "<", "BufferMovePrevious", silent) map("n", ">", "BufferMoveNext", silent) map("n", "bp", "BufferPin", silent) map("n", "bw", "BufferClose", silent) map("n", "b$", "BufferLast", silent) map("n", "bb", "BufferPick", silent) map("n", "bd", "BufferPickDelete", silent) for i = 1, 9 do map("n", ("%d"):format(i), ("BufferGoto %d"):format(i), silent) end -- Flash map({ "n", "x", "o" }, "s", function() require("flash").jump() end, { desc = "Flash" }) map({ "n", "x", "o" }, "S", function() require("flash").treesitter() end, { desc = "Flash Treesitter" }) map("o", "r", function() require("flash").remote() end, { desc = "Remote Flash" }) map({ "o", "x" }, "R", function() require("flash").treesitter_search() end, { desc = "Treesitter Search" }) map("c", "", function() require("flash").toggle() end, { desc = "Toggle Flash Search" }) -- Spell map("n", "sc", function() vim.wo.spell = not vim.wo.spell vim.notify("Spell: " .. (vim.wo.spell and "ON" or "OFF")) end, { desc = "Toggle spell" }) map("n", "sl", function() local cur = vim.opt.spelllang:get()[1] or "" local new = cur == "en" and "de" or "en" vim.opt.spelllang = new vim.notify("Spell lang: " .. new) end, { desc = "Switch spell language" })