local M = {} local map = vim.keymap.set function M.lsp(buffer, client) local opts = { buffer = buffer, silent = true, } map("n", "gd", vim.lsp.buf.definition, opts) map("n", "gD", vim.lsp.buf.declaration, opts) map("n", "gr", vim.lsp.buf.references, opts) map("n", "gi", vim.lsp.buf.implementation, opts) map("n", "K", vim.lsp.buf.hover, opts) map("n", "rn", vim.lsp.buf.rename, opts) map("n", "ca", vim.lsp.buf.code_action, opts) map("n", "cf", function() require("conform").format({ async = true, lsp_fallback = true, }) end, opts) local function set_c_bindings() if client and client.name == "clangd" then map("n", "hs", "ClangdSwitchSourceHeader", opts) end end local function set_python_bindings() if client and (client.name == "basedpyright" or client.name == "pyright" or client.name == "pylsp") then local function run_pytest() vim.cmd("botright split | terminal pytest") end map("n", "", run_pytest, { desc = "Run pytest (nur Python-Projekt)", }) end end set_c_bindings() set_python_bindings() end function M.gitsigns() map("n", "tb", require("gitsigns").toggle_current_line_blame) end function M.copilot() if vim.fn.exists(":Copilot") == 0 then return end map("n", "ct", function() local status = vim.fn["copilot#Enabled"]() if status == 1 then vim.cmd("Copilot disable") print("Copilot disabled") else vim.cmd("Copilot enable") print("Copilot enabled") end end, { desc = "Copilot Toggle" }) map("n", "ce", function() vim.cmd("Copilot enable") print("Copilot enabled") end, { desc = "Copilot Enable" }) map("n", "cd", function() vim.cmd("Copilot disable") print("Copilot disabled") end, { desc = "Copilot Disable" }) map("n", "cs", function() vim.cmd("Copilot status") end, { desc = "Copilot Status" }) end function M.global() local opts = { silent = true, } map("n", "ö", "}", opts) map("n", "ä", "{", opts) -- besseres Verhalten von -- https://vimrc-dissection.blogspot.com/2009/02/fixing-pageup-and-pagedown.html map("n", "", "1000", opts) map("n", "", "1000", opts) map("i", "", "1000", opts) map("i", "", "1000", opts) -- Verschiebe Zeilen mit Alt+j / Alt+k -- MacOS: Terminal → Einstellungen → Profile → Tastatur → "Option als Meta-Taste verwenden" map("n", "", ":m .+1==", opts) map("n", "", ":m .-2==", opts) map("i", "", ":m .+1==gi", opts) map("i", "", ":m .-2==gi", opts) map("x", "", ":m '>+1gv=gv", opts) map("x", "", ":m '<-2gv=gv", opts) -- besseres Verhalten in umbrochenen Texten map({ "n", "x", "o" }, "j", function() return vim.v.count == 0 and "gj" or "j" end, { expr = true, silent = true }) map({ "n", "x", "o" }, "k", function() return vim.v.count == 0 and "gk" or "k" end, { expr = true, silent = true }) map("n", "", "make", opts) -- Kombinationen mit Leader-Key map("n", "K", function() vim.diagnostic.open_float({ scope = "cursor", border = "rounded" }) end, opts) map("n", "q", vim.diagnostic.setloclist, opts) map("n", "ts", function() vim.opt_local.spell = not vim.opt_local.spell:get() end, { desc = "Toggle spell checking" }) map("n", "[d", function() vim.diagnostic.jump_prev({ wrap = false }) end, opts) map("n", "]d", function() vim.diagnostic.jump_next({ wrap = false }) end, opts) map("n", "[e", function() vim.diagnostic.jump_prev({ severity = vim.diagnostic.severity.ERROR, wrap = false, }) end, opts) map("n", "]e", function() vim.diagnostic.jump_next({ severity = vim.diagnostic.severity.ERROR, wrap = false, }) end, opts) end return M