-- Plugin-independent maps. Plugin maps live in their spec's `keys`. local map = vim.keymap.set map({ "n", "x" }, "y", '"+y', { desc = "Yank to system clipboard" }) map({ "n", "x" }, "p", '"+p', { desc = "Paste from system clipboard" }) -- Diagnostic jumps without [ and ] (QWERTZ). The default [d / ]d still work. map("n", "n", function() vim.diagnostic.jump({ count = vim.v.count1, float = true }) end, { desc = "Next diagnostic" }) map("n", "N", function() vim.diagnostic.jump({ count = -vim.v.count1, float = true }) end, { desc = "Previous diagnostic" }) -- Buffer and window navigation map("n", "", "bprevious", { desc = "Prev buffer" }) map("n", "", "bnext", { desc = "Next buffer" }) for _, dir in ipairs({ "h", "j", "k", "l" }) do map("n", "", "" .. dir, { desc = "Window " .. dir }) map("t", "", "" .. dir, { desc = "Window " .. dir }) end map("n", "", "resize +2", { desc = "Window taller" }) map("n", "", "resize -2", { desc = "Window shorter" }) map("n", "", "vertical resize -2", { desc = "Window narrower" }) map("n", "", "vertical resize +2", { desc = "Window wider" }) -- Editing helpers map({ "i", "n" }, "", "noh", { desc = "Escape and clear hlsearch" }) map("n", "", "zz", { desc = "Half page down" }) map("n", "", "zz", { desc = "Half page up" }) map("x", "J", ":m '>+1gv=gv", { desc = "Move selection down" }) map("x", "K", ":m '<-2gv=gv", { desc = "Move selection up" }) map("x", "<", "", ">gv", { desc = "Indent right" }) map("x", "P", '"_dP', { desc = "Paste keep register" }) -- Selection by treesitter node, LSP selection range as fallback map({ "n", "x", "o" }, "", function() if vim.treesitter.get_parser(nil, nil, { error = false }) then require("vim.treesitter._select").select_parent(vim.v.count1) else vim.lsp.buf.selection_range(vim.v.count1) end end, { desc = "Select parent node" }) map({ "n", "x", "o" }, "", function() if vim.treesitter.get_parser(nil, nil, { error = false }) then require("vim.treesitter._select").select_child(vim.v.count1) else vim.lsp.buf.selection_range(-vim.v.count1) end end, { desc = "Select child node" }) map("n", "fl", function() local value = vim.fn.fnamemodify(vim.fn.expand("%"), ":~:.") .. ":" .. vim.fn.line(".") vim.fn.setreg("+", value) vim.notify("Copied " .. value) end, { desc = "Copy path:line" })