local function map(mode, lhs, rhs, opts) opts = opts or {} opts.silent = opts.silent ~= false vim.keymap.set(mode, lhs, rhs, opts) end local opts = { noremap = true, silent = true } -- Space as leader map("n", "", "", opts) vim.g.mapleader = " " vim.g.maplocalleader = " " -- Modes -- normal_mode = "n", insert_mode = "i", visual_mode = "v", -- visual_block_mode = "x", term_mode = "t", command_mode = "c", -- Clear search, diff update and redraw map({ "i", "n" }, "", "noh", { desc = "Escape and clear hlsearch" }) map({ "i", "c" }, "", "") map({ "i", "c" }, "", "") map("n", "r", vim.lsp.buf.rename) map("n", "`", "'", { noremap = true }) -- better marks map("n", "H", "^", { desc = "Jump to line start" }) map("n", "L", "$", { desc = "Jump to line end" }) -- Visual overwrite paste map({ "v", "x" }, "p", '"_dP', opts) -- Do not copy on x map({ "v", "x" }, "x", '"_x', opts) map("n", "X", '"_D', opts) map({ "v", "x" }, "X", '"_d', opts) -- Select all map("n", "", "ggVG", { desc = "Select all" }) map("i", "", "ggVG", { desc = "Select all" }) -- Move text up and down map({ "v", "x" }, "K", ":move '<-2gv-gv", opts) map({ "v", "x" }, "J", ":move '>+1gv-gv", opts) -- Line operations map("n", "", ":m .-2==", { desc = "Move line up" }) map("n", "", ":m .+1==", { desc = "Move line down" }) map("i", "", ":m .-2==gi", { desc = "Move line up" }) map("i", "", ":m .+1==gi", { desc = "Move line down" }) map("v", "", ":m '<-2gv=gv", { desc = "Move selection up" }) map("v", "", ":m '>+1gv=gv", { desc = "Move selection down" }) -- Line manipulation map("n", "", ">>", { desc = "Indent line" }) map("n", "", "<<", { desc = "Unindent line" }) map("i", "", ">>", { desc = "Indent line" }) map("i", "", "<<", { desc = "Unindent line" }) -- Quick word operations map("n", "", "db", { desc = "Delete word backward" }) map("i", "", "", { desc = "Delete word backward" }) map("n", "", "dw", { desc = "Delete word forward" }) map("i", "", "dw", { desc = "Delete word forward" }) map("n", "d", '"_d', { desc = "Delete without replacing clipboard" }) map("n", "x", '"_x', { desc = "Cut without replacing clipboard" }) map("n", "c", '"_c', { desc = "Change without replacing clipboard" }) map("v", "p", '"_dP', { desc = "Paste without replacing clipboard" }) --insert the following characters around the visual selection map("v", "(", "s()Pll", { desc = "wrap selection with parens" }) map("v", "[", "s[]Pll", { desc = "wrap selection with square braces" }) map("v", "{", "s{}Pll", { desc = "wrap selection with curly braces" }) map("v", "'", "s''Pll", { desc = "wrap selection with single quotes" }) map("v", '"', 's""Pll', { desc = "wrap selection with double quotes" }) -- Insert mode cursor movement with Ctrl+hjkl map("i", "", "", { desc = "Move to end of previous line" }) map("i", "", "", { desc = "Move cursor down" }) map("i", "", "", { desc = "Move cursor up" }) map("i", "", "", { desc = "Move cursor right" }) -- toggle inlay hints vim.keymap.set("n", "th", function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled()) end) -- No arrow navigation vim.api.nvim_set_keymap("n", "", "", opts) vim.api.nvim_set_keymap("n", "", "", opts) vim.api.nvim_set_keymap("n", "", "", opts) vim.api.nvim_set_keymap("n", "", "", opts) vim.api.nvim_set_keymap("v", "", "", opts) vim.api.nvim_set_keymap("v", "", "", opts) vim.api.nvim_set_keymap("v", "", "", opts) vim.api.nvim_set_keymap("v", "", "", opts) vim.api.nvim_set_keymap("i", "", "", opts) vim.api.nvim_set_keymap("i", "", "", opts) vim.api.nvim_set_keymap("i", "", "", opts) vim.api.nvim_set_keymap("i", "", "", opts)