-- vim.g.mapleader = " " -- This has to be configured inside lazy.lua due to telescope loading before this takes effect vim.cmd("command! W w") -- Navigation vim.keymap.set("n", "Q", "", { desc = "Do not quit" }) -- Do not quit :D vim.keymap.set("i", "", "") -- Exit insert mode with C-c vim.keymap.set("n", "", "silent !tmux display-popup -E \"tmuxss -i\"") -- open tmuxss switcher vim.keymap.set("n", "-", "Oil", { desc = "Open parent directory" }) -- open file viewer vim.keymap.set("n", "", "copen"); -- Open Quickfixlist vim.keymap.set("t", "", "") -- use Esc to escape terminal vim.keymap.set("n", "", "zz") -- Move up a page while keeping the cursor centered vim.keymap.set("n", "", "zz") -- Move down a page while keeping the cursor centered vim.keymap.set("n", "n", "nzzzv") -- Jump to next occurance and center cursor vim.keymap.set("n", "N", "Nzzzv") -- Jump to previous occurance and center cursor vim.keymap.set("n", "", "cprevzz") -- Previous Quickfixlist entry vim.keymap.set("n", "", "cnextzz") -- Next Quickfixlist entry vim.keymap.set("n", "", "tabnext +") -- Next tab vim.keymap.set("n", "", "tabnext -") -- Previous Tab vim.keymap.set("n", "", "tabnew") -- Create new Tab vim.keymap.set("n", "", "tabclose") -- Close the current Tab -- Text editing vim.keymap.set("v", "J", ":m '>+1gv=gv") -- Move selected text up one line vim.keymap.set("v", "K", ":m '<-2gv=gv") -- Move selected text down one line vim.keymap.set("n", "J", "mzJ`z") -- Remove newline characte on current line vim.keymap.set("n", "c", ":w:!cargorun") -- Quick Cargo run vim.keymap.set("n", "f", function() vim.lsp.buf.format() end) -- fuck this thing for _, mode in ipairs({ "n", "v", "i" }) do vim.keymap.set(mode, "", function() end) vim.keymap.set(mode, "<2-RightMouse>", function() end) vim.keymap.set(mode, "<3-RightMouse>", function() end) vim.keymap.set(mode, "<4-RightMouse>", function() end) end -- Goated: Edit the word under the cursor using a substitute vim.keymap.set("n", "s", ":%s/\\<\\>//gI") -- Yanking and Pasting -- Yank to + register (system clipboard) vim.keymap.set("n", "y", "\"+y") vim.keymap.set("v", "y", "\"+y") vim.keymap.set("n", "Y", "\"+Y") -- Delete to void register (no clipboard) vim.keymap.set("v", "d", "\"_d") vim.keymap.set("v", "dd", "\"_d") -- currently conflict with searches -- vim.keymap.set("x", "P", "\"_dP") -- Paste before without moving selection into the yank register -- vim.keymap.set("x", "p", "\"_dp") -- Paste after without moving selection into the yank register -- Macros vim.keymap.set("n", "x", "!chmod +x %", { silent = true }) -- format a markdown table inside visual selection vim.api.nvim_create_user_command("Mdtf", function(opts) vim.cmd(string.format("%d,%d!column -t -s '|' -o '|'", opts.line1, opts.line2)) end, { range = true, }) vim.keymap.set("v", "mt", ":!column -t -s '|' -o '|'", { desc = "Format markdown table" }) -- Lua editing vim.keymap.set("n", "l", "source %") -- source the current buffer vim.keymap.set("n", "l", ":.lua") -- source the current line vim.keymap.set("v", "l", ":lua") -- source the visual selection local function swap_words() local start = vim.fn.getpos("'<")[2] local finish = vim.fn.getpos("'>")[2] local w1 = vim.fn.input("Word 1: ") local w2 = vim.fn.input("Word 2: ") if w1 == "" or w2 == "" then return end local lines = vim.api.nvim_buf_get_lines(0, start - 1, finish, false) for i, line in ipairs(lines) do line = line:gsub(vim.pesc(w1), "__TMP__") line = line:gsub(vim.pesc(w2), w1) line = line:gsub("__TMP__", w2) lines[i] = line end vim.api.nvim_buf_set_lines(0, start - 1, finish, false, lines) end vim.keymap.set("v", "ws", swap_words, { desc = "Swap two words in selection" }) vim.keymap.set("n", "ws", swap_words, { desc = "Swap two words in selection" })