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") map("n", "", "Pick keymaps") -- 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) -- Bufferline map("n", "", "BufferLineCyclePrev", silent) map("n", "", "BufferLineCycleNext", silent) map("n", "[b", "BufferLineCyclePrev", silent) map("n", "]b", "BufferLineCycleNext", silent) map("n", "<", "BufferLineMovePrev", silent) map("n", ">", "BufferLineMoveNext", silent) map("n", "bp", "BufferLineTogglePin", { desc = "Toggle pin" }) map("n", "bP", "BufferLineGroupClose ungrouped", { desc = "Close non-pinned" }) map("n", "bo", "BufferLineCloseOthers", { desc = "Close others" }) map("n", "br", "BufferLineCloseRight", { desc = "Close right" }) map("n", "bl", "BufferLineCloseLeft", { desc = "Close left" }) map("n", "bd", "bdelete", { desc = "Delete buffer" }) map("n", "bb", "BufferLinePick", { desc = "Pick buffer" }) map("n", "bse", "BufferLineSortByExtension", { desc = "Sort by extension" }) map("n", "bsd", "BufferLineSortByDirectory", { desc = "Sort by directory" }) map("n", "bsr", "BufferLineSortByRelativeDirectory", { desc = "Sort by relative dir" }) map("n", "bst", "BufferLineSortByTabs", { desc = "Sort by tabs" }) for i = 1, 9 do map("n", ("%d"):format(i), ("BufferLineGoToBuffer %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" })