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 local bk = vim.fn.has("macunix") == 1 and "M" or "A" local bar = { [","] = "BufferPrevious", ["."] = "BufferNext", ["<"] = "BufferMovePrevious", [">"] = "BufferMoveNext", ["p"] = "BufferPin", ["w"] = "BufferClose", ["0"] = "BufferLast", } for k, cmd in pairs(bar) do map("n", ("<%s-%s>"):format(bk, k), ("%s"):format(cmd), silent) end for i = 1, 9 do map("n", ("<%s-%d>"):format(bk, i), ("BufferGoto %d"):format(i), silent) end map("n", "", "BufferPick", silent) map("n", "", "BufferPickDelete", silent) -- 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" })